Chilkat Online Tools

delphiDll / Egyptian eInvoicing SDK R1.5 / 1. Authenticate POS

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_AddHeader(req,'presharedkey','C68FEC13-FE34-4839-89F9-ADB0D678CFE0');
CkHttpRequest_AddHeader(req,'posmodelframework','1');
CkHttpRequest_AddHeader(req,'posserial','Test_SerialNo1');
CkHttpRequest_AddHeader(req,'pososversion','IOS');

resp := CkHttp_PostUrlEncoded(http,'https://domain.com/connect/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(jsonParam2);
CkJsonObject_Dispose(jsonParam3);

Curl Command

curl -X POST
	-H "posserial: Test_SerialNo1"
	-H "pososversion: IOS"
	-H "posmodelframework: 1"
	-H "presharedkey: C68FEC13-FE34-4839-89F9-ADB0D678CFE0"
	--data-urlencode 'grant_type=client_credentials'
	--data-urlencode 'client_id={{clientId}}'
	--data-urlencode 'client_secret={{clientSecret}}'
https://domain.com/connect/token

Postman Collection Item JSON

{
  "name": "1. Authenticate POS",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "var json = pm.response.json()\r",
          "var accesstoken=json.access_token\r",
          "pm.environment.set(\"generatedAccessToken\",accesstoken);\r",
          "\r",
          "pm.test(\"Status code is 200\", function () {\r",
          "    pm.response.to.have.status(200);\r",
          "});"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "posserial",
        "value": "Test_SerialNo1",
        "type": "text"
      },
      {
        "key": "pososversion",
        "value": "IOS",
        "type": "text"
      },
      {
        "key": "posmodelframework",
        "value": "1",
        "type": "text",
        "disabled": true
      },
      {
        "key": "presharedkey",
        "value": "C68FEC13-FE34-4839-89F9-ADB0D678CFE0",
        "type": "text"
      }
    ],
    "body": {
      "mode": "urlencoded",
      "urlencoded": [
        {
          "key": "grant_type",
          "value": "client_credentials",
          "type": "text"
        },
        {
          "key": "client_id",
          "value": "{{clientId}}",
          "type": "text"
        },
        {
          "key": "client_secret",
          "value": "{{clientSecret}}",
          "type": "text"
        }
      ]
    },
    "url": {
      "raw": "{{idSrvBaseUrl}}/connect/token",
      "host": [
        "{{idSrvBaseUrl}}"
      ],
      "path": [
        "connect",
        "token"
      ]
    }
  },
  "response": [
  ]
}