Chilkat Online Tools

delphiDll / DocuSign eSignature REST API / 02 JWT Access Token

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
req: HCkHttpRequest;
jsonParam1: 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();

jsonParam1 := CkJsonObject_Create();
CkHttpRequest_AddParam(req,'assertion',CkJsonObject__emit(jsonParam1));
CkHttpRequest_AddParam(req,'grant_type','urn:ietf:params:oauth:grant-type:jwt-bearer');

CkHttpRequest_AddHeader(req,'Authorization','Basic {{encodedKeys}}');

resp := CkHttp_PostUrlEncoded(http,'https://{{hostenv}}/oauth/token',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(jsonParam1);

Curl Command

curl -X POST
	-H "Authorization: Basic {{encodedKeys}}"
	--data-urlencode 'assertion={{assertionHere}}'
	--data-urlencode 'grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer'
https://{{hostenv}}/oauth/token

Postman Collection Item JSON

{
  "name": "02 JWT Access Token",
  "event": [
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          "var jsonData = JSON.parse(responseBody);",
          "postman.setEnvironmentVariable(\"accessToken\", jsonData.access_token);"
        ]
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Authorization",
        "value": "Basic {{encodedKeys}}"
      }
    ],
    "body": {
      "mode": "urlencoded",
      "urlencoded": [
        {
          "key": "assertion",
          "value": "{{assertionHere}}"
        },
        {
          "key": "grant_type",
          "value": "urn:ietf:params:oauth:grant-type:jwt-bearer"
        }
      ]
    },
    "url": {
      "raw": "https://{{hostenv}}/oauth/token",
      "protocol": "https",
      "host": [
        "{{hostenv}}"
      ],
      "path": [
        "oauth",
        "token"
      ]
    }
  },
  "response": [
  ]
}