Chilkat Online Tools

unicodeC / EPC 2.0 - Partner Sandbox - 19.4 November [External] / [Partner] Send Acknowledgment Response

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkStringBuilderW sbRequestBody;
    HCkHttpResponseW resp;

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

    http = CkHttpW_Create();

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

    // The following JSON is sent in the request body.

    // {
    //   "status": "processing",
    //   "partnerStatus": "Order Accepted",
    //   "referenceNumber": "ORDER_REFERENCE_NUMBER",
    //   "respondingParty ": {
    //     "name": "COMPANY_NAME",
    //     "address": "COMPANY_STREET_ADDRESS",
    //     "city": "COMPANY_CITY",
    //     "state": "COMPANY_STATE",
    //     "postalCode": "COMPANY_ZIP_CODE",
    //     "pointOfContact": {
    //       "name": "CONTACT_NAME",
    //       "role": "CONTACT_ROLE",
    //       "phone": "CONTACT_PHONE_NUMBER",
    //       "email": "CONTACT_EMAIL"
    //     }
    //   }
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"status",L"processing");
    CkJsonObjectW_UpdateString(json,L"partnerStatus",L"Order Accepted");
    CkJsonObjectW_UpdateString(json,L"referenceNumber",L"ORDER_REFERENCE_NUMBER");
    CkJsonObjectW_UpdateString(json,L"\"respondingParty \".name",L"COMPANY_NAME");
    CkJsonObjectW_UpdateString(json,L"\"respondingParty \".address",L"COMPANY_STREET_ADDRESS");
    CkJsonObjectW_UpdateString(json,L"\"respondingParty \".city",L"COMPANY_CITY");
    CkJsonObjectW_UpdateString(json,L"\"respondingParty \".state",L"COMPANY_STATE");
    CkJsonObjectW_UpdateString(json,L"\"respondingParty \".postalCode",L"COMPANY_ZIP_CODE");
    CkJsonObjectW_UpdateString(json,L"\"respondingParty \".pointOfContact.name",L"CONTACT_NAME");
    CkJsonObjectW_UpdateString(json,L"\"respondingParty \".pointOfContact.role",L"CONTACT_ROLE");
    CkJsonObjectW_UpdateString(json,L"\"respondingParty \".pointOfContact.phone",L"CONTACT_PHONE_NUMBER");
    CkJsonObjectW_UpdateString(json,L"\"respondingParty \".pointOfContact.email",L"CONTACT_EMAIL");

    // Adds the "Authorization: Bearer {{partner_token}}" header.
    CkHttpW_putAuthToken(http,L"{{partner_token}}");
    CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");

    sbRequestBody = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(json,sbRequestBody);

    resp = CkHttpW_PTextSb(http,L"PATCH",L"https://domain.com/",sbRequestBody,L"utf-8",L"application/json",FALSE,FALSE);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(sbRequestBody);

    }

Curl Command

curl -X PATCH
	-H "Authorization: Bearer {{partner_token}}"
	-H "Content-Type: application/json"
	-d '{
    "status": "processing",
    "partnerStatus": "Order Accepted",
    "referenceNumber": "ORDER_REFERENCE_NUMBER",
    "respondingParty ": {
        "name": "COMPANY_NAME",
        "address": "COMPANY_STREET_ADDRESS",
        "city": "COMPANY_CITY",
        "state": "COMPANY_STATE",
        "postalCode": "COMPANY_ZIP_CODE",
        "pointOfContact": {
            "name": "CONTACT_NAME",
            "role": "CONTACT_ROLE",
            "phone": "CONTACT_PHONE_NUMBER",
            "email": "CONTACT_EMAIL"
        }
    }
}'
https://domain.com/

Postman Collection Item JSON

{
  "name": "[Partner] Send Acknowledgment Response",
  "_postman_id": "1165b237-e991-481e-bd7b-f05d17b2de2f",
  "request": {
    "method": "PATCH",
    "header": [
      {
        "key": "Authorization",
        "value": "Bearer {{partner_token}}",
        "type": "text"
      },
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "value": "application/json",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"status\": \"processing\",\n    \"partnerStatus\": \"Order Accepted\",\n    \"referenceNumber\": \"ORDER_REFERENCE_NUMBER\",\n    \"respondingParty \": {\n        \"name\": \"COMPANY_NAME\",\n        \"address\": \"COMPANY_STREET_ADDRESS\",\n        \"city\": \"COMPANY_CITY\",\n        \"state\": \"COMPANY_STATE\",\n        \"postalCode\": \"COMPANY_ZIP_CODE\",\n        \"pointOfContact\": {\n            \"name\": \"CONTACT_NAME\",\n            \"role\": \"CONTACT_ROLE\",\n            \"phone\": \"CONTACT_PHONE_NUMBER\",\n            \"email\": \"CONTACT_EMAIL\"\n        }\n    }\n}"
    },
    "url": "{{api_host}}/partner/v2/transactions/{{transaction_id}}/response"
  },
  "response": [
  ]
}