Back to Collection Items
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoHttp
Boolean iSuccess
Variant vJson
Handle hoJson
Variant vResp
Handle hoResp
String sTemp1
Integer iTemp1
Boolean bTemp1
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "text": "EVENT_DESCRIPTION",
// "type": "EVENT_TYPE",
// "comments": "EVENT_COMMENTS",
// "resources": [
// {
// "id": "{{partner_resource_id}}",
// "name": "{{partner_resource_name}}",
// "mimeType": "{{partner_resource_mimeType}}"
// }
// ]
// }
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "text" "EVENT_DESCRIPTION" To iSuccess
Get ComUpdateString Of hoJson "type" "EVENT_TYPE" To iSuccess
Get ComUpdateString Of hoJson "comments" "EVENT_COMMENTS" To iSuccess
Get ComUpdateString Of hoJson "resources[0].id" "{{partner_resource_id}}" To iSuccess
Get ComUpdateString Of hoJson "resources[0].name" "{{partner_resource_name}}" To iSuccess
Get ComUpdateString Of hoJson "resources[0].mimeType" "{{partner_resource_mimeType}}" To iSuccess
// Adds the "Authorization: Bearer {{partner_token}}" header.
Set ComAuthToken Of hoHttp To "{{partner_token}}"
Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"
Get pvComObject of hoJson to vJson
Get ComPostJson3 Of hoHttp "https://domain.com/" "application/json" vJson To vResp
If (IsComObject(vResp)) Begin
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
Set pvComObject Of hoResp To vResp
End
Get ComLastMethodSuccess Of hoHttp To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComStatusCode Of hoResp To iTemp1
Showln iTemp1
Get ComBodyStr Of hoResp To sTemp1
Showln sTemp1
Send Destroy of hoResp
End_Procedure
Curl Command
curl -X POST
-H "Authorization: Bearer {{partner_token}}"
-H "Content-Type: application/json"
-d '{
"text": "EVENT_DESCRIPTION",
"type": "EVENT_TYPE",
"comments": "EVENT_COMMENTS",
"resources": [
{
"id": "{{partner_resource_id}}",
"name": "{{partner_resource_name}}",
"mimeType": "{{partner_resource_mimeType}}"
}
]
}'
https://domain.com/
Postman Collection Item JSON
{
"name": "[Partner] Create a Transaction Event",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"// Extract Event identifier from response body",
"var jsonData = JSON.parse(responseBody);",
"var eventId = jsonData.id;",
"",
"// Set to an environment variable",
"postman.setEnvironmentVariable(\"event_id\", eventId);"
]
}
}
],
"_postman_id": "13de08d0-ce97-4bfa-9b95-518e06b6becc",
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"type": "text",
"value": "Bearer {{partner_token}}"
},
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"text\": \"EVENT_DESCRIPTION\",\n \"type\": \"EVENT_TYPE\",\n \"comments\": \"EVENT_COMMENTS\",\n \"resources\": [\n {\n \"id\": \"{{partner_resource_id}}\",\n \"name\": \"{{partner_resource_name}}\",\n \"mimeType\": \"{{partner_resource_mimeType}}\"\n }\n ]\n}"
},
"url": "{{api_host}}/partner/v2/transactions/{{transaction_id}}/events"
},
"response": [
]
}