Chilkat Online Tools

unicodeC / Reloadly API / Order

Back to Collection Items

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

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    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.

    // {
    //   "productId": 120,
    //   "countryCode": "US",
    //   "quantity": 1,
    //   "unitPrice": 1,
    //   "customIdentifier": "obucks10",
    //   "senderName": "John Doe",
    //   "recipientEmail": "anyone@email.com",
    //   "recipientPhoneDetails": {
    //     "countryCode": "ES",
    //     "phoneNumber": "657829900"
    //   }
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateInt(json,L"productId",120);
    CkJsonObjectW_UpdateString(json,L"countryCode",L"US");
    CkJsonObjectW_UpdateInt(json,L"quantity",1);
    CkJsonObjectW_UpdateInt(json,L"unitPrice",1);
    CkJsonObjectW_UpdateString(json,L"customIdentifier",L"obucks10");
    CkJsonObjectW_UpdateString(json,L"senderName",L"John Doe");
    CkJsonObjectW_UpdateString(json,L"recipientEmail",L"anyone@email.com");
    CkJsonObjectW_UpdateString(json,L"recipientPhoneDetails.countryCode",L"ES");
    CkJsonObjectW_UpdateString(json,L"recipientPhoneDetails.phoneNumber",L"657829900");

    CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
    // Adds the "Authorization: Bearer YOUR_ACCESS_TOKEN_HERE" header.
    CkHttpW_putAuthToken(http,L"YOUR_ACCESS_TOKEN_HERE");
    CkHttpW_SetRequestHeader(http,L"Accept",L"application/com.reloadly.giftcards-v1+json");

    resp = CkHttpW_PostJson3(http,L"https://giftcards.reloadly.com/orders",L"application/json",json);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        return;
    }

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


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);

    }

Curl Command

curl -X POST
	-H "Authorization: Bearer YOUR_ACCESS_TOKEN_HERE"
	-H "Accept: application/com.reloadly.giftcards-v1+json"
	-H "Content-Type: application/json"
	-d '{
    "productId": 120,
    "countryCode": "US",
    "quantity": 1,
    "unitPrice": 1,
    "customIdentifier": "obucks10",
    "senderName": "John Doe",
    "recipientEmail": "anyone@email.com",
     "recipientPhoneDetails": {
        "countryCode": "ES",
        "phoneNumber": "657829900"
    }
}'
https://giftcards.reloadly.com/orders

Postman Collection Item JSON

{
  "name": "Order",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Authorization",
        "value": "Bearer YOUR_ACCESS_TOKEN_HERE",
        "type": "text"
      },
      {
        "key": "Accept",
        "value": "application/com.reloadly.giftcards-v1+json",
        "type": "text"
      },
      {
        "key": "Content-Type",
        "value": "application/json",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\r\n    \"productId\": 120,\r\n    \"countryCode\": \"US\",\r\n    \"quantity\": 1,\r\n    \"unitPrice\": 1,\r\n    \"customIdentifier\": \"obucks10\",\r\n    \"senderName\": \"John Doe\",\r\n    \"recipientEmail\": \"anyone@email.com\",\r\n     \"recipientPhoneDetails\": {\r\n        \"countryCode\": \"ES\",\r\n        \"phoneNumber\": \"657829900\"\r\n    }\r\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "https://giftcards.reloadly.com/orders",
      "protocol": "https",
      "host": [
        "giftcards",
        "reloadly",
        "com"
      ],
      "path": [
        "orders"
      ]
    }
  },
  "response": [
  ]
}