Chilkat Online Tools

PureBasic / Reloadly API / Order

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ; 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.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateInt(json,"productId",120)
    CkJsonObject::ckUpdateString(json,"countryCode","US")
    CkJsonObject::ckUpdateInt(json,"quantity",1)
    CkJsonObject::ckUpdateInt(json,"unitPrice",1)
    CkJsonObject::ckUpdateString(json,"customIdentifier","obucks10")
    CkJsonObject::ckUpdateString(json,"senderName","John Doe")
    CkJsonObject::ckUpdateString(json,"recipientEmail","anyone@email.com")
    CkJsonObject::ckUpdateString(json,"recipientPhoneDetails.countryCode","ES")
    CkJsonObject::ckUpdateString(json,"recipientPhoneDetails.phoneNumber","657829900")

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

    resp.i = CkHttp::ckPostJson3(http,"https://giftcards.reloadly.com/orders","application/json",json)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)
    CkHttpResponse::ckDispose(resp)



    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(json)


    ProcedureReturn
EndProcedure

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": [
  ]
}