Chilkat Online Tools

delphiDll / EPC 2.0 - Partner Sandbox - 19.4 November [External] / [Partner] Create Partner Authentication Token

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
req: HCkHttpRequest;
jsonParam2: HCkJsonObject;
jsonParam3: HCkJsonObject;
resp: HCkHttpResponse;

begin
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

http := CkHttp_Create();

req := CkHttpRequest_Create();
CkHttpRequest_AddParam(req,'grant_type','client_credentials');

jsonParam2 := CkJsonObject_Create();
CkHttpRequest_AddParam(req,'client_id',CkJsonObject__emit(jsonParam2));

jsonParam3 := CkJsonObject_Create();
CkHttpRequest_AddParam(req,'client_secret',CkJsonObject__emit(jsonParam3));
CkHttpRequest_AddParam(req,'scope','pc pcapi');

resp := CkHttp_PostUrlEncoded(http,'https://domain.com/',req);
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

Memo1.Lines.Add(IntToStr(CkHttpResponse_getStatusCode(resp)));
Memo1.Lines.Add(CkHttpResponse__bodyStr(resp));
CkHttpResponse_Dispose(resp);

CkHttp_Dispose(http);
CkHttpRequest_Dispose(req);
CkJsonObject_Dispose(jsonParam2);
CkJsonObject_Dispose(jsonParam3);

Curl Command

curl -X POST
	-H "Content-Type: application/x-www-form-urlencoded"
	--data-urlencode 'grant_type=client_credentials'
	--data-urlencode 'client_id={{partner_client_id}}'
	--data-urlencode 'client_secret={{partner_client_secret}}'
	--data-urlencode 'scope=pc pcapi'
https://domain.com/

Postman Collection Item JSON

{
  "name": "[Partner] Create Partner Authentication Token",
  "event": [
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          "// Extract oAuth Token from response body",
          "var jsonData = JSON.parse(responseBody);",
          "var partnerToken = jsonData.access_token;",
          "",
          "// Set to an environment variable",
          "postman.setEnvironmentVariable(\"partner_token\", partnerToken);"
        ]
      }
    }
  ],
  "_postman_id": "6f420d0f-ef65-40dc-a870-e21ff2522ccf",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "value": "application/x-www-form-urlencoded",
        "type": "text"
      }
    ],
    "body": {
      "mode": "urlencoded",
      "urlencoded": [
        {
          "key": "grant_type",
          "value": "client_credentials",
          "type": "text"
        },
        {
          "key": "client_id",
          "value": "{{partner_client_id}}",
          "type": "text"
        },
        {
          "key": "client_secret",
          "value": "{{partner_client_secret}}",
          "type": "text"
        },
        {
          "key": "scope",
          "value": "pc pcapi",
          "type": "text"
        }
      ]
    },
    "url": "{{api_host}}/oauth2/v1/token"
  },
  "response": [
  ]
}