Chilkat Online Tools

C / Egyptian eInvoicing SDK R1.5 / 1. Login as Taxpayer System

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkHttpRequest.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkHttpRequest req;
    HCkJsonObject jsonParam2;
    HCkJsonObject jsonParam3;
    HCkHttpResponse resp;

    // 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","InvoicingAPI");

    resp = CkHttp_PostUrlEncoded(http,"https://domain.com/connect/token",req);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkHttpRequest_Dispose(req);
        CkJsonObject_Dispose(jsonParam2);
        CkJsonObject_Dispose(jsonParam3);
        return;
    }

    printf("%d\n",CkHttpResponse_getStatusCode(resp));
    printf("%s\n",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={{clientId}}'
	--data-urlencode 'client_secret={{clientSecret}}'
	--data-urlencode 'scope=InvoicingAPI'
https://domain.com/connect/token

Postman Collection Item JSON

{
  "name": "1. Login as Taxpayer System",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "\r",
          "pm.test(\"Status code is 200\", function () {\r",
          "var jsonData = JSON.parse(responseBody);\r",
          "pm.environment.set(\"generatedAccessToken\", jsonData.access_token);\r",
          "});\r",
          "\r",
          "\r",
          "\r",
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/x-www-form-urlencoded",
        "type": "text"
      },
      {
        "key": "",
        "value": "",
        "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"
        },
        {
          "key": "scope",
          "value": "InvoicingAPI",
          "type": "text"
        }
      ]
    },
    "url": {
      "raw": "{{idSrvBaseUrl}}/connect/token",
      "host": [
        "{{idSrvBaseUrl}}"
      ],
      "path": [
        "connect",
        "token"
      ]
    }
  },
  "response": [
  ]
}