Chilkat Online Tools

SQL Server / LHDN MyInvois SDK / Login as Intermediary System

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    DECLARE @req int
    -- Use "Chilkat_9_5_0.HttpRequest" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.HttpRequest', @req OUT

    EXEC sp_OAMethod @req, 'AddParam', NULL, 'grant_type', 'client_credentials'
    EXEC sp_OAMethod @req, 'AddParam', NULL, 'scope', 'InvoicingAPI'

    EXEC sp_OAMethod @req, 'AddHeader', NULL, 'client_id', '{{clientId}}'
    EXEC sp_OAMethod @req, 'AddHeader', NULL, 'grant_type', 'client_credentials'
    EXEC sp_OAMethod @req, 'AddHeader', NULL, 'onbehalfof', '100015840'
    EXEC sp_OAMethod @req, 'AddHeader', NULL, 'client_secret', '{{clientSecret}}'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostUrlEncoded', @resp OUT, 'https://{{apiBaseUrl}}/connect/token', @req
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @req
        RETURN
      END

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @req


END
GO

Curl Command

curl -X POST
	-H "client_id: {{clientId}}"
	-H "client_secret: {{clientSecret}}"
	-H "onbehalfof: 100015840"
	-H "grant_type: client_credentials"
	--data-urlencode 'grant_type=client_credentials'
	--data-urlencode 'scope=InvoicingAPI'
https://{{apiBaseUrl}}/connect/token

Postman Collection Item JSON

{
  "name": "Login as Intermediary System",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "client_id",
        "value": "{{clientId}}",
        "type": "text",
        "uuid": "df451b49-4e2b-4868-a180-1d01df266117"
      },
      {
        "key": "client_secret",
        "value": "{{clientSecret}}",
        "type": "text",
        "uuid": "c693de12-7723-4be2-aec1-00c1cdc7a797"
      },
      {
        "key": "onbehalfof",
        "value": "100015840",
        "type": "text",
        "uuid": "d55cb4b6-59f8-4f19-95a2-db6780b8152d"
      },
      {
        "key": "grant_type",
        "value": "client_credentials",
        "type": "text",
        "uuid": "7386ca83-cce5-4b62-bcb0-06e464a3b67f"
      }
    ],
    "body": {
      "mode": "urlencoded",
      "urlencoded": [
        {
          "key": "grant_type",
          "value": "client_credentials",
          "type": "text"
        },
        {
          "key": "scope",
          "value": "InvoicingAPI",
          "type": "text"
        }
      ]
    },
    "url": {
      "raw": "https://{{apiBaseUrl}}/connect/token",
      "protocol": "https",
      "host": [
        "{{apiBaseUrl}}"
      ],
      "path": [
        "connect",
        "token"
      ]
    }
  },
  "response": [
  ]
}