Chilkat Online Tools

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

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Req
oleobject loo_JsonParam2
oleobject loo_JsonParam3
oleobject loo_Resp

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Req = create oleobject
li_rc = loo_Req.ConnectToNewObject("Chilkat_9_5_0.HttpRequest")

loo_Req.AddParam("grant_type","client_credentials")

loo_JsonParam2 = create oleobject
li_rc = loo_JsonParam2.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_Req.AddParam("client_id",loo_JsonParam2.Emit())

loo_JsonParam3 = create oleobject
li_rc = loo_JsonParam3.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_Req.AddParam("client_secret",loo_JsonParam3.Emit())
loo_Req.AddParam("scope","InvoicingAPI")

loo_Resp = loo_Http.PostUrlEncoded("https://domain.com/connect/token",loo_Req)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Req
    destroy loo_JsonParam2
    destroy loo_JsonParam3
    return
end if

Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr
destroy loo_Resp


destroy loo_Http
destroy loo_Req
destroy loo_JsonParam2
destroy loo_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": [
  ]
}