Chilkat Online Tools

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

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vReq
    Handle hoReq
    Handle hoJsonParam2
    Handle hoJsonParam3
    Variant vResp
    Handle hoResp
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    Get Create (RefClass(cComChilkatHttpRequest)) To hoReq
    If (Not(IsComObjectCreated(hoReq))) Begin
        Send CreateComObject of hoReq
    End
    Send ComAddParam To hoReq "grant_type" "client_credentials"

    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonParam2
    If (Not(IsComObjectCreated(hoJsonParam2))) Begin
        Send CreateComObject of hoJsonParam2
    End
    Get ComEmit Of hoJsonParam2 To sTemp1
    Send ComAddParam To hoReq "client_id" sTemp1

    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonParam3
    If (Not(IsComObjectCreated(hoJsonParam3))) Begin
        Send CreateComObject of hoJsonParam3
    End
    Get ComEmit Of hoJsonParam3 To sTemp1
    Send ComAddParam To hoReq "client_secret" sTemp1

    Send ComAddHeader To hoReq "presharedkey" "C68FEC13-FE34-4839-89F9-ADB0D678CFE0"
    Send ComAddHeader To hoReq "posmodelframework" "1"
    Send ComAddHeader To hoReq "posserial" "Test_SerialNo1"
    Send ComAddHeader To hoReq "pososversion" "IOS"

    Get pvComObject of hoReq to vReq
    Get ComPostUrlEncoded Of hoHttp "https://domain.com/connect/token" vReq To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Showln iTemp1
    Get ComBodyStr Of hoResp To sTemp1
    Showln sTemp1
    Send Destroy of hoResp


End_Procedure

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": [
  ]
}