Chilkat Online Tools

Ruby / Salesforce Platform APIs / Cancel a Voucher

Back to Collection Items

require 'chilkat'

# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

http = Chilkat::CkHttp.new()

# Use this online tool to generate code from sample JSON: Generate Code to Create JSON

# The following JSON is sent in the request body.

# {
#   "processParameters": [
#     {
#       "MemberId": "0lMxx00000000BJEAY",
#       "VoucherId": "0kdxx000000000B245"
#     }
#   ]
# }

json = Chilkat::CkJsonObject.new()
json.UpdateString("processParameters[0].MemberId","0lMxx00000000BJEAY")
json.UpdateString("processParameters[0].VoucherId","0kdxx000000000B245")

# Adds the "Authorization: Bearer <access_token>" header.
http.put_AuthToken("<access_token>")

# resp is a CkHttpResponse
resp = http.PostJson3("https://domain.com/services/data/v{{version}}/connect/loyalty/programs/:loyaltyProgramName/program-processes/:processName","application/json",json)
if (http.get_LastMethodSuccess() == false)
    print http.lastErrorText() + "\n";
    exit
end

print resp.get_StatusCode().to_s() + "\n";
print resp.bodyStr() + "\n";

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '{
   "processParameters":[
      {
         "MemberId":"0lMxx00000000BJEAY",
         "VoucherId":"0kdxx000000000B245"
      }
   ]
}'
https://domain.com/services/data/v{{version}}/connect/loyalty/programs/:loyaltyProgramName/program-processes/:processName

Postman Collection Item JSON

{
  "name": "Cancel a Voucher",
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "exec": [
          "//pm.variables.set('loyaltyProgramName','xyz');",
          "pm.variables.set('processName','CancelVoucher');"
        ],
        "type": "text/javascript",
        "packages": {}
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n   \"processParameters\":[\n      {\n         \"MemberId\":\"0lMxx00000000BJEAY\",\n         \"VoucherId\":\"0kdxx000000000B245\"\n      }\n   ]\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/connect/loyalty/programs/:loyaltyProgramName/program-processes/:processName",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "connect",
        "loyalty",
        "programs",
        ":loyaltyProgramName",
        "program-processes",
        ":processName"
      ],
      "variable": [
        {
          "key": "loyaltyProgramName",
          "value": "NTO Insider"
        },
        {
          "key": "processName",
          "value": ""
        }
      ]
    },
    "description": "Standard Documentation:\n\n[https://developer.salesforce.com/docs/atlas.en-us.loyalty.meta/loyalty/connect_resources_cancel_voucher.htm](https://developer.salesforce.com/docs/atlas.en-us.loyalty.meta/loyalty/connect_resources_cancel_voucher.htm)\n\nIn the Pre-request. Script Tab, make changes in the variables value accordingly with the real Process Name to invoke."
  },
  "response": [
  ]
}