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'
DECLARE @jsonParam2 int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonParam2 OUT
EXEC sp_OAMethod @jsonParam2, 'Emit', @sTmp0 OUT
EXEC sp_OAMethod @req, 'AddParam', NULL, 'client_id', @sTmp0
DECLARE @jsonParam3 int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonParam3 OUT
EXEC sp_OAMethod @jsonParam3, 'Emit', @sTmp0 OUT
EXEC sp_OAMethod @req, 'AddParam', NULL, 'client_secret', @sTmp0
EXEC sp_OAMethod @req, 'AddHeader', NULL, 'presharedkey', 'C68FEC13-FE34-4839-89F9-ADB0D678CFE0'
EXEC sp_OAMethod @req, 'AddHeader', NULL, 'posmodelframework', '1'
EXEC sp_OAMethod @req, 'AddHeader', NULL, 'posserial', 'Test_SerialNo1'
EXEC sp_OAMethod @req, 'AddHeader', NULL, 'pososversion', 'IOS'
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
EXEC @hr = sp_OADestroy @jsonParam2
EXEC @hr = sp_OADestroy @jsonParam3
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
EXEC @hr = sp_OADestroy @jsonParam2
EXEC @hr = sp_OADestroy @jsonParam3
END
GO
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": [
]
}