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
-- 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
-- Adds the "Authorization: Bearer <access_token>" header.
EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
DECLARE @sbResponseBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://domain.com/services/data/v{{version}}/connect/loyalty/member/:memberId/memberbenefits', @sbResponseBody
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
RETURN
END
DECLARE @jResp int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT
EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
EXEC sp_OASetProperty @jResp, 'EmitCompact', 0
PRINT 'Response Body:'
EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
PRINT @sTmp0
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @http, 'LastStatus', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
RETURN
END
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- {
-- "memberBenefits": [
-- {
-- "benefitId": "0jiJ80000008OIFIA2",
-- "benefitName": "Free Shipping",
-- "benefitTypeId": "0jhJ80000008OI5IAM",
-- "benefitTypeName": "Shipping",
-- "createdRecordId": null,
-- "createdRecordName": null,
-- "description": null,
-- "endDate": null,
-- "isActive": true,
-- "memberBenefitStatus": null,
-- "startDate": null
-- },
-- {
-- "benefitId": "0jiJ80000008OI5IAM",
-- "benefitName": "5% of Discount",
-- "benefitTypeId": "0jhJ80000008OIAIA2",
-- "benefitTypeName": "Discount Percentage",
-- "createdRecordId": null,
-- "createdRecordName": null,
-- "description": null,
-- "endDate": null,
-- "isActive": true,
-- "memberBenefitStatus": null,
-- "startDate": null
-- }
-- ]
-- }
-- Sample code for parsing the JSON response...
-- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
DECLARE @benefitId nvarchar(4000)
DECLARE @benefitName nvarchar(4000)
DECLARE @benefitTypeId nvarchar(4000)
DECLARE @benefitTypeName nvarchar(4000)
DECLARE @createdRecordId nvarchar(4000)
DECLARE @createdRecordName nvarchar(4000)
DECLARE @description nvarchar(4000)
DECLARE @endDate nvarchar(4000)
DECLARE @isActive int
DECLARE @memberBenefitStatus nvarchar(4000)
DECLARE @startDate nvarchar(4000)
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'memberBenefits'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @benefitId OUT, 'memberBenefits[i].benefitId'
EXEC sp_OAMethod @jResp, 'StringOf', @benefitName OUT, 'memberBenefits[i].benefitName'
EXEC sp_OAMethod @jResp, 'StringOf', @benefitTypeId OUT, 'memberBenefits[i].benefitTypeId'
EXEC sp_OAMethod @jResp, 'StringOf', @benefitTypeName OUT, 'memberBenefits[i].benefitTypeName'
EXEC sp_OAMethod @jResp, 'StringOf', @createdRecordId OUT, 'memberBenefits[i].createdRecordId'
EXEC sp_OAMethod @jResp, 'StringOf', @createdRecordName OUT, 'memberBenefits[i].createdRecordName'
EXEC sp_OAMethod @jResp, 'StringOf', @description OUT, 'memberBenefits[i].description'
EXEC sp_OAMethod @jResp, 'StringOf', @endDate OUT, 'memberBenefits[i].endDate'
EXEC sp_OAMethod @jResp, 'BoolOf', @isActive OUT, 'memberBenefits[i].isActive'
EXEC sp_OAMethod @jResp, 'StringOf', @memberBenefitStatus OUT, 'memberBenefits[i].memberBenefitStatus'
EXEC sp_OAMethod @jResp, 'StringOf', @startDate OUT, 'memberBenefits[i].startDate'
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
Curl Command
curl -X GET
-H "Authorization: Bearer <access_token>"
https://domain.com/services/data/v{{version}}/connect/loyalty/member/:memberId/memberbenefits
Postman Collection Item JSON
{
"name": "Member Benefits",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [
],
"body": {
"mode": "raw",
"raw": "",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{_endpoint}}/services/data/v{{version}}/connect/loyalty/member/:memberId/memberbenefits",
"host": [
"{{_endpoint}}"
],
"path": [
"services",
"data",
"v{{version}}",
"connect",
"loyalty",
"member",
":memberId",
"memberbenefits"
],
"variable": [
{
"key": "memberId",
"value": ""
}
]
},
"description": "Standard Documentation:\n\n[https://developer.salesforce.com/docs/atlas.en-us.loyalty.meta/loyalty/connect_resources_member_benefits.htm](https://developer.salesforce.com/docs/atlas.en-us.loyalty.meta/loyalty/connect_resources_member_benefits.htm)"
},
"response": [
{
"name": "Member Benefits",
"originalRequest": {
"method": "GET",
"header": [
{
"key": "Authorization",
"value": "Bearer {{accessToken}}"
}
],
"body": {
"mode": "raw",
"raw": "",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{_endpoint}}/services/data/v{{version}}/connect/loyalty/member/:memberId/memberbenefits",
"host": [
"{{_endpoint}}"
],
"path": [
"services",
"data",
"v{{version}}",
"connect",
"loyalty",
"member",
":memberId",
"memberbenefits"
],
"variable": [
{
"key": "memberId",
"value": "0lMJ8000000CaRMMA0"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Date",
"value": "Wed, 22 May 2024 16:11:06 GMT"
},
{
"key": "Strict-Transport-Security",
"value": "max-age=63072000; includeSubDomains"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-Robots-Tag",
"value": "none"
},
{
"key": "Cache-Control",
"value": "no-cache,must-revalidate,max-age=0,no-store,private"
},
{
"key": "Content-Type",
"value": "application/json;charset=UTF-8"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "Content-Encoding",
"value": "gzip"
},
{
"key": "Transfer-Encoding",
"value": "chunked"
}
],
"cookie": [
],
"body": "{\n \"memberBenefits\": [\n {\n \"benefitId\": \"0jiJ80000008OIFIA2\",\n \"benefitName\": \"Free Shipping\",\n \"benefitTypeId\": \"0jhJ80000008OI5IAM\",\n \"benefitTypeName\": \"Shipping\",\n \"createdRecordId\": null,\n \"createdRecordName\": null,\n \"description\": null,\n \"endDate\": null,\n \"isActive\": true,\n \"memberBenefitStatus\": null,\n \"startDate\": null\n },\n {\n \"benefitId\": \"0jiJ80000008OI5IAM\",\n \"benefitName\": \"5% of Discount\",\n \"benefitTypeId\": \"0jhJ80000008OIAIA2\",\n \"benefitTypeName\": \"Discount Percentage\",\n \"createdRecordId\": null,\n \"createdRecordName\": null,\n \"description\": null,\n \"endDate\": null,\n \"isActive\": true,\n \"memberBenefitStatus\": null,\n \"startDate\": null\n }\n ]\n}"
}
]
}