Authenticate with token

After authentication a token will be issued and that token is used on further requests to the Partner API.

Overview

Method: POST: This specifies the HTTPS request method, which is "POST" in this case.

URL: https://uat-idsrv.spenn.com/token: This is the base URL where the POST request is being sent to.

Headers: Headers are additional pieces of information sent along with the HTTPS request to provide context or instructions. In this case, there is one header specified: Content-Type: application/x-www-form-urlencoded

Parameters

Parameters needs to be given in the request body encoded as application/x-www-form-urlencoded using appropriate url encoding.

  • Parameters: grant_type=api_key
  • api_key=XXXXXX client_id=SpennBusinessApiKey
  • client_secret=1234
  • audience=SpennBusiness

Sample Authentication:

import requests

# Define the URL
url = 'https://uat-idsrv.spenn.com/token'

# Define the headers
headers = {
    'Content-Type': 'application/x-www-form-urlencoded'
}

# Define the request data
data = {
    'grant_type': 'api_key',
    'api_key': 'JpqLGcuiXXXXXXqRyyoWo=',
    'client_id': 'SpennBusinessApiKey',
    'client_secret': '1234',
    'audience': 'SpennBusiness'
}

# Make the POST request
response = requests.post(url, headers=headers, data=data)

# Check the response
if response.status_code == 200:
    print("Success! Response:")
    print(response.text)
else:
    print(f"Request failed with status code {response.status_code}")
    print(response.text)

const fetch = require('node-fetch'); // If running in Node.js

// Define the URL
const url = 'https://uat-idsrv.spenn.com/token';

// Define the request headers
const headers = {
  'Content-Type': 'application/x-www-form-urlencoded'
};

// Define the request data
const data = new URLSearchParams();
data.append('grant_type', 'api_key');
data.append('api_key', 'JpqLGcuiXXXXXXqRyyoWo=');
data.append('client_id', 'SpennBusinessApiKey');
data.append('client_secret', '1234');
data.append('audience', 'SpennBusiness');

// Make the POST request
fetch(url, {
  method: 'POST',
  headers: headers,
  body: data
})
  .then(response => response.text())
  .then(responseText => {
    console.log('Success! Response:');
    console.log(responseText);
  })
  .catch(error => {
    console.error('Request failed:', error);
  });

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpClientExample {
    public static void main(String[] args) {
        try {
            // Define the URL
            String url = "https://uat-idsrv.spenn.com/token";

            // Create a connection
            URL obj = new URL(url);
            HttpURLConnection con = (HttpURLConnection) obj.openConnection();

            // Set the request method to POST
            con.setRequestMethod("POST");

            // Set request headers
            con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

            // Define the request data
            String data = "grant_type=api_key&api_key=JpqLGcuiXXXXXXqRyyoWo=&client_id=SpennBusinessApiKey&client_secret=1234&audience=SpennBusiness";

            // Enable input/output streams
            con.setDoOutput(true);
            DataOutputStream wr = new DataOutputStream(con.getOutputStream());
            wr.writeBytes(data);
            wr.flush();
            wr.close();

            // Get the response code
            int responseCode = con.getResponseCode();

            // Read the response
            if (responseCode == 200) {
                BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
                String inputLine;
                StringBuffer response = new StringBuffer();

                while ((inputLine = in.readLine()) != null) {
                    response.append(inputLine);
                }
                in.close();

                System.out.println("Success! Response:");
                System.out.println(response.toString());
            } else {
                System.out.println("Request failed with status code " + responseCode);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

👍

Sample Response

{
"access_token": "eyJhbG...NrEQ41w",
"token_type": "bearer",
"expires_in": 1199,
"refresh_token": "84c8113XXXXXXX4279533c4b", 
"clientId": "SpennBusinessPartner",
"audience": "SpennBusiness",
"type": "user",
".issued": "Tue, 31 Mar 2020 09:58:45 GMT", 
".expires": "Tue, 31 Mar 2020 10:18:45 GMT"
}