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
-- Use this online tool to generate code from sample JSON: Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- {
-- "name": "Carson Wentz",
-- "address": "100 S. Broad Street",
-- "city": "Philadelphia",
-- "region": "PA",
-- "country": "US",
-- "postal": "19103",
-- "merchid": "{{merchid}}",
-- "account": "{{account}}",
-- "expiry": "{{expiry}}",
-- "currency": "{{currency}}",
-- "profile": "{{profileid}}",
-- "profileupdate": "Y",
-- "defaultacct": "N"
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'name', 'Carson Wentz'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'address', '100 S. Broad Street'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'city', 'Philadelphia'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'region', 'PA'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'country', 'US'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'postal', '19103'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'merchid', '{{merchid}}'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'account', '{{account}}'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'expiry', '{{expiry}}'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'currency', '{{currency}}'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'profile', '{{profileid}}'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'profileupdate', 'Y'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'defaultacct', 'N'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', '{{Authorization}}'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
DECLARE @sbRequestBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbRequestBody OUT
EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody
DECLARE @resp int
EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'PUT', 'https://domain.com/profile', @sbRequestBody, 'utf-8', 'application/json', 0, 0
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 @json
EXEC @hr = sp_OADestroy @sbRequestBody
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 @json
EXEC @hr = sp_OADestroy @sbRequestBody
END
GO
Curl Command
curl -X PUT
-H "Authorization: {{Authorization}}"
-H "Content-Type: application/json"
-d '{
"name": "Carson Wentz",
"address": "100 S. Broad Street",
"city": "Philadelphia",
"region": "PA",
"country": "US",
"postal": "19103",
"merchid": "{{merchid}}",
"account": "{{account}}",
"expiry": "{{expiry}}",
"currency": "{{currency}}",
"profile": "{{profileid}}",
"profileupdate": "Y",
"defaultacct": "N"
}'
https://domain.com/profile
Postman Collection Item JSON
{
"name": "Profile (New account/token/card)",
"event": [
{
"listen": "test",
"script": {
"exec": [
"var jsonData = JSON.parse(responseBody);",
"postman.setEnvironmentVariable(\"profileid\", jsonData.profileid);",
"var jsonData = JSON.parse(responseBody);",
"postman.setEnvironmentVariable(\"acctid\", jsonData.acctid);"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "PUT",
"header": [
{
"key": "Authorization",
"value": "{{Authorization}}"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"Carson Wentz\",\n \"address\": \"100 S. Broad Street\",\n \"city\": \"Philadelphia\",\n \"region\": \"PA\",\n \"country\": \"US\",\n \"postal\": \"19103\",\n \"merchid\": \"{{merchid}}\",\n \"account\": \"{{account}}\",\n \"expiry\": \"{{expiry}}\",\n \"currency\": \"{{currency}}\",\n \"profile\": \"{{profileid}}\",\n \"profileupdate\": \"Y\",\n \"defaultacct\": \"N\"\n}"
},
"url": {
"raw": "{{url}}/profile",
"host": [
"{{url}}"
],
"path": [
"profile"
]
},
"description": "[Profile Documentation](https://developer.cardconnect.com/cardconnect-api#profile)\n\n**Notes:** \n* To create subaccounts on an existing profile\n* acctid = n + 1"
},
"response": [
]
}