SQL Server / LHDN MyInvois SDK / Login as Taxpayer 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, 'client_id', 'cc446489-7217-4791-a4d2-b7d14a36b8a5'
EXEC sp_OAMethod @req, 'AddParam', NULL, 'client_secret', 'a7d0addf-86d4-4d7a-bd44-623f8dda9108'
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, 'client_secret', '{{clientSecret}}'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostUrlEncoded', @resp OUT, 'https://domain.com/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 "grant_type: client_credentials"
--data-urlencode 'client_id=cc446489-7217-4791-a4d2-b7d14a36b8a5'
--data-urlencode 'client_secret=a7d0addf-86d4-4d7a-bd44-623f8dda9108'
--data-urlencode 'grant_type=client_credentials'
--data-urlencode 'scope=InvoicingAPI'
https://domain.com/connect/token
Postman Collection Item JSON
{
"name": "Login as Taxpayer System",
"protocolProfileBehavior": {
"disabledSystemHeaders": {
"connection": true,
"accept-encoding": true,
"accept": true,
"user-agent": true,
"host": true
}
},
"request": {
"method": "POST",
"header": [
{
"key": "client_id",
"value": "{{clientId}}",
"type": "text",
"uuid": "ee303c9d-1311-4e81-95ac-d9479dd2b5c0",
"disabled": true
},
{
"key": "client_secret",
"value": "{{clientSecret}}",
"type": "text",
"uuid": "091d3a0c-149b-47c1-ae6a-efd5cac1f983",
"disabled": true
},
{
"key": "grant_type",
"value": "client_credentials",
"type": "text",
"uuid": "4c8439d5-eff6-4d7f-a66c-5d8d3f1a0938",
"disabled": true
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "client_id",
"value": "cc446489-7217-4791-a4d2-b7d14a36b8a5",
"type": "text"
},
{
"key": "client_secret",
"value": "a7d0addf-86d4-4d7a-bd44-623f8dda9108",
"type": "text"
},
{
"key": "grant_type",
"value": "client_credentials",
"type": "text"
},
{
"key": "scope",
"value": "InvoicingAPI",
"type": "text"
}
]
},
"url": {
"raw": "{{idSrvBaseUrl}}/connect/token",
"host": [
"{{idSrvBaseUrl}}"
],
"path": [
"connect",
"token"
]
}
},
"response": [
]
}