Chilkat Online Tools

SQL Server / Salesforce Platform APIs / Transaction Journals Simulation

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": [
    --     {
    --       "CurrencyIsoCode": "EUR",
    --       "ActivityDate": "2022-01-04T12:45:19Z",
    --       "JournalDate": "2022-01-04T00:45:19Z",
    --       "Brand": "",
    --       "Establishment": "Apple",
    --       "ExternalTransactionNumber": "P1-981950",
    --       "JournalTypeId": "0lET10000004CQp",
    --       "LoyaltyProgramId": "0lpT10000004CdN",
    --       "MemberId": "0lMT10000004CfA",
    --       "TransactionAmount": "117",
    --       "TransactionLocation": "HitechCity",
    --       "VoucherCode": "",
    --       "Origin": "asdf",
    --       "Distance": "5",
    --       "Destination": "Hyderabad",
    --       "FlightNumber": "SF-Ran-001",
    --       "Status": "Pending"
    --     }
    --   ],
    --   "runSetting": {
    --     "isSimulation": true
    --   }
    -- }

    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].CurrencyIsoCode', 'EUR'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].ActivityDate', '2022-01-04T12:45:19Z'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].JournalDate', '2022-01-04T00:45:19Z'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].Brand', ''
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].Establishment', 'Apple'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].ExternalTransactionNumber', 'P1-981950'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].JournalTypeId', '0lET10000004CQp'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].LoyaltyProgramId', '0lpT10000004CdN'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].MemberId', '0lMT10000004CfA'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].TransactionAmount', '117'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].TransactionLocation', 'HitechCity'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].VoucherCode', ''
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].Origin', 'asdf'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].Distance', '5'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].Destination', 'Hyderabad'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].FlightNumber', 'SF-Ran-001'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactionJournals[0].Status', 'Pending'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'runSetting.isSimulation', 1

    -- 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": [
    {
      "CurrencyIsoCode": "EUR",
      "ActivityDate": "2022-01-04T12:45:19Z",
      "JournalDate": "2022-01-04T00:45:19Z",
      "Brand": "",
      "Establishment": "Apple",
      "ExternalTransactionNumber": "P1-981950",
      "JournalTypeId": "0lET10000004CQp",
      "LoyaltyProgramId": "0lpT10000004CdN",
      "MemberId": "0lMT10000004CfA",
      "TransactionAmount": "117",
      "TransactionLocation": "HitechCity",
      "VoucherCode": "",
      "Origin": "asdf",
      "Distance": "5",
      "Destination": "Hyderabad",
      "FlightNumber": "SF-Ran-001",
      "Status": "Pending"
    }
  ],
  "runSetting": {
    "isSimulation": true
  }
}'
https://domain.com/services/data/v{{version}}/connect/realtime/loyalty/programs/:loyaltyProgramName

Postman Collection Item JSON

{
  "name": "Transaction Journals Simulation",
  "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      \"CurrencyIsoCode\": \"EUR\",\n      \"ActivityDate\": \"2022-01-04T12:45:19Z\",\n      \"JournalDate\": \"2022-01-04T00:45:19Z\",\n      \"Brand\": \"\",\n      \"Establishment\": \"Apple\",\n      \"ExternalTransactionNumber\": \"P1-981950\",\n      \"JournalTypeId\": \"0lET10000004CQp\",\n      \"LoyaltyProgramId\": \"0lpT10000004CdN\",\n      \"MemberId\": \"0lMT10000004CfA\",\n      \"TransactionAmount\": \"117\",\n      \"TransactionLocation\": \"HitechCity\",\n      \"VoucherCode\": \"\",\n      \"Origin\": \"asdf\",\n      \"Distance\": \"5\",\n      \"Destination\": \"Hyderabad\",\n      \"FlightNumber\": \"SF-Ran-001\",\n      \"Status\": \"Pending\"\n    }\n  ],\n  \"runSetting\": {\n    \"isSimulation\": true\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_process_simulation.htm](https://developer.salesforce.com/docs/atlas.en-us.loyalty.meta/loyalty/connect_resources_loyalty_program_process_simulation.htm)"
  },
  "response": [
  ]
}