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
DECLARE @jsonParam1 int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonParam1 OUT
EXEC sp_OAMethod @jsonParam1, 'Emit', @sTmp0 OUT
EXEC sp_OAMethod @req, 'AddParam', NULL, 'username', @sTmp0
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, 'password', @sTmp0
EXEC sp_OAMethod @req, 'AddParam', NULL, 'grant_type', 'password'
DECLARE @jsonParam4 int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonParam4 OUT
EXEC sp_OAMethod @jsonParam4, 'Emit', @sTmp0 OUT
EXEC sp_OAMethod @req, 'AddParam', NULL, 'client_id', @sTmp0
DECLARE @jsonParam5 int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonParam5 OUT
EXEC sp_OAMethod @jsonParam5, 'Emit', @sTmp0 OUT
EXEC sp_OAMethod @req, 'AddParam', NULL, 'client_secret', @sTmp0
EXEC sp_OAMethod @req, 'AddParam', NULL, 'scope', 'lp'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostUrlEncoded', @resp OUT, 'https://domain.com/', @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 @jsonParam1
EXEC @hr = sp_OADestroy @jsonParam2
EXEC @hr = sp_OADestroy @jsonParam4
EXEC @hr = sp_OADestroy @jsonParam5
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 @jsonParam1
EXEC @hr = sp_OADestroy @jsonParam2
EXEC @hr = sp_OADestroy @jsonParam4
EXEC @hr = sp_OADestroy @jsonParam5
END
GO
Curl Command
curl -X POST
-H "Content-Type: application/x-www-form-urlencoded"
--data-urlencode 'username={{encompass_username}}@encompass:{{encompass_instance_id}}'
--data-urlencode 'password={{encompass_password}}'
--data-urlencode 'grant_type=password'
--data-urlencode 'client_id={{lender_client_id}}'
--data-urlencode 'client_secret={{lender_client_secret}}'
--data-urlencode 'scope=lp'
https://domain.com/
Postman Collection Item JSON
{
"name": "[Lender] Create Lender Authentication Token",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"// Extract Lender oAuth token from response body",
"var jsonData = JSON.parse(responseBody);",
"var lenderToken = jsonData.access_token;",
"",
"// Set to an environment variable",
"postman.setEnvironmentVariable(\"lender_token\", lenderToken);"
]
}
}
],
"_postman_id": "dcaf78e5-430f-47e0-9d98-ef4313352ace",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "username",
"value": "{{encompass_username}}@encompass:{{encompass_instance_id}}",
"type": "text"
},
{
"key": "password",
"value": "{{encompass_password}}",
"type": "text"
},
{
"key": "grant_type",
"value": "password",
"type": "text"
},
{
"key": "client_id",
"value": "{{lender_client_id}}",
"type": "text"
},
{
"key": "client_secret",
"value": "{{lender_client_secret}}",
"type": "text"
},
{
"key": "scope",
"value": "lp",
"type": "text"
}
]
},
"url": "{{api_host}}/oauth2/v1/token"
},
"response": [
]
}