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.
-- {
-- "transactionJournals": [
-- {
-- "ActivityDate": "2023-11-27T12:45:19Z",
-- "JournalTypeId": "0lERM00000001Bb2AI",
-- "LoyaltyProgramId": "0lpRM00000002YTYAY",
-- "MemberId": "0lMRM0000002Fmu2AE",
-- "Status": "Pending",
-- "appliedPromotions": [
-- {
-- "promotionId": "0c8RM0000004FiXYAU",
-- "rewards": [
-- {
-- "rewardType": "Discount",
-- "discountAmount": 15
-- },
-- {
-- "rewardType": "Points",
-- "loyaltyProgramCurrencyName": "Coins",
-- "points": 100,
-- "relatedInformation": "Test",
-- "notes": "Test"
-- },
-- {
-- "rewardType": "Voucher",
-- "voucherDefinitionName": "10% Discount Voucher",
-- "voucherExpirationDate": "2023-12-15",
-- "voucherEffectiveDate": "2023-11-29",
-- "notes": "Test"
-- },
-- {
-- "rewardType": "Badge",
-- "loyaltyProgramBadgeName": "Gen AI Badge",
-- "memberBadgeStatus": "Active",
-- "badgeValidityEndDate": "2023-12-15",
-- "reason": "Test"
-- },
-- {
-- "rewardType": "Game",
-- "gameDefinitionName": "TestGame"
-- }
-- ]
-- }
-- ]
-- }
-- ]
-- }
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, 'transactionJournals[0].ActivityDate', '2023-11-27T12:45:19Z'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].JournalTypeId', '0lERM00000001Bb2AI'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].LoyaltyProgramId', '0lpRM00000002YTYAY'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].MemberId', '0lMRM0000002Fmu2AE'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].Status', 'Pending'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].appliedPromotions[0].promotionId', '0c8RM0000004FiXYAU'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].appliedPromotions[0].rewards[0].rewardType', 'Discount'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'transactionJournals[0].appliedPromotions[0].rewards[0].discountAmount', 15
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].appliedPromotions[0].rewards[1].rewardType', 'Points'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].appliedPromotions[0].rewards[1].loyaltyProgramCurrencyName', 'Coins'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'transactionJournals[0].appliedPromotions[0].rewards[1].points', 100
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].appliedPromotions[0].rewards[1].relatedInformation', 'Test'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].appliedPromotions[0].rewards[1].notes', 'Test'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].appliedPromotions[0].rewards[2].rewardType', 'Voucher'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].appliedPromotions[0].rewards[2].voucherDefinitionName', '10% Discount Voucher'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].appliedPromotions[0].rewards[2].voucherExpirationDate', '2023-12-15'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].appliedPromotions[0].rewards[2].voucherEffectiveDate', '2023-11-29'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].appliedPromotions[0].rewards[2].notes', 'Test'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].appliedPromotions[0].rewards[3].rewardType', 'Badge'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].appliedPromotions[0].rewards[3].loyaltyProgramBadgeName', 'Gen AI Badge'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].appliedPromotions[0].rewards[3].memberBadgeStatus', 'Active'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].appliedPromotions[0].rewards[3].badgeValidityEndDate', '2023-12-15'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].appliedPromotions[0].rewards[3].reason', 'Test'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].appliedPromotions[0].rewards[4].rewardType', 'Game'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].appliedPromotions[0].rewards[4].gameDefinitionName', 'TestGame'
-- Adds the "Authorization: Bearer <access_token>" header.
EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://domain.com/services/data/v{{version}}/connect/realtime/loyalty/programs/:loyaltyProgramName', 'application/json', @json
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
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
END
GO
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-d '{
"transactionJournals":[
{
"ActivityDate":"2023-11-27T12:45:19Z",
"JournalTypeId":"0lERM00000001Bb2AI",
"LoyaltyProgramId":"0lpRM00000002YTYAY",
"MemberId":"0lMRM0000002Fmu2AE",
"Status":"Pending",
"appliedPromotions":[
{
"promotionId":"0c8RM0000004FiXYAU",
"rewards":[
{
"rewardType":"Discount",
"discountAmount":15
},
{
"rewardType":"Points",
"loyaltyProgramCurrencyName":"Coins",
"points":100,
"relatedInformation":"Test",
"notes":"Test"
},
{
"rewardType":"Voucher",
"voucherDefinitionName":"10% Discount Voucher",
"voucherExpirationDate":"2023-12-15",
"voucherEffectiveDate":"2023-11-29",
"notes":"Test"
},
{
"rewardType":"Badge",
"loyaltyProgramBadgeName":"Gen AI Badge",
"memberBadgeStatus":"Active",
"badgeValidityEndDate":"2023-12-15",
"reason":"Test"
},
{
"rewardType":"Game",
"gameDefinitionName":"TestGame"
}
]
}
]
}
]
}'
https://domain.com/services/data/v{{version}}/connect/realtime/loyalty/programs/:loyaltyProgramName
Postman Collection Item JSON
{
"name": "Transaction Journals Execution",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"var moment = require('moment');",
"pm.globals.set('currentDatetime', moment().format((\"YYYY-MM-DDTHH:MM:SS\")));"
],
"type": "text/javascript",
"packages": {}
}
}
],
"request": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"transactionJournals\":[\n {\n \"ActivityDate\":\"2023-11-27T12:45:19Z\",\n \"JournalTypeId\":\"0lERM00000001Bb2AI\",\n \"LoyaltyProgramId\":\"0lpRM00000002YTYAY\",\n \"MemberId\":\"0lMRM0000002Fmu2AE\",\n \"Status\":\"Pending\",\n \"appliedPromotions\":[\n {\n \"promotionId\":\"0c8RM0000004FiXYAU\",\n \"rewards\":[\n {\n \"rewardType\":\"Discount\",\n \"discountAmount\":15\n },\n {\n \"rewardType\":\"Points\",\n \"loyaltyProgramCurrencyName\":\"Coins\",\n \"points\":100,\n \"relatedInformation\":\"Test\",\n \"notes\":\"Test\"\n },\n {\n \"rewardType\":\"Voucher\",\n \"voucherDefinitionName\":\"10% Discount Voucher\",\n \"voucherExpirationDate\":\"2023-12-15\",\n \"voucherEffectiveDate\":\"2023-11-29\",\n \"notes\":\"Test\"\n },\n {\n \"rewardType\":\"Badge\",\n \"loyaltyProgramBadgeName\":\"Gen AI Badge\",\n \"memberBadgeStatus\":\"Active\",\n \"badgeValidityEndDate\":\"2023-12-15\",\n \"reason\":\"Test\"\n },\n {\n \"rewardType\":\"Game\",\n \"gameDefinitionName\":\"TestGame\"\n }\n ]\n }\n ]\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{_endpoint}}/services/data/v{{version}}/connect/realtime/loyalty/programs/:loyaltyProgramName",
"host": [
"{{_endpoint}}"
],
"path": [
"services",
"data",
"v{{version}}",
"connect",
"realtime",
"loyalty",
"programs",
":loyaltyProgramName"
],
"variable": [
{
"key": "loyaltyProgramName",
"value": ""
}
]
},
"description": "Standard Documentation:\n\n[https://developer.salesforce.com/docs/atlas.en-us.loyalty.meta/loyalty/connect_resources_loyalty_program_realtime.htm](https://developer.salesforce.com/docs/atlas.en-us.loyalty.meta/loyalty/connect_resources_loyalty_program_realtime.htm)"
},
"response": [
]
}