Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>
#include <C_CkHttpResponse.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkJsonObject json;
HCkStringBuilder sbRequestBody;
HCkHttpResponse resp;
HCkStringBuilder sbResponseBody;
HCkJsonObject jResp;
int respStatusCode;
const char *Amount;
const char *v_Currency;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_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.
// {
// "amount": 100,
// "currency": "usd"
// }
json = CkJsonObject_Create();
CkJsonObject_UpdateInt(json,"amount",100);
CkJsonObject_UpdateString(json,"currency","usd");
CkHttp_SetRequestHeader(http,"API-Key","{{API_KEY}}");
CkHttp_SetRequestHeader(http,"Content-Type","application/json");
sbRequestBody = CkStringBuilder_Create();
CkJsonObject_EmitSb(json,sbRequestBody);
resp = CkHttp_PTextSb(http,"PUT","https://api.shipengine.com/v1/carriers/se-963358/add_funds",sbRequestBody,"utf-8","application/json",FALSE,FALSE);
if (CkHttp_getLastMethodSuccess(http) == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
return;
}
sbResponseBody = CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);
jResp = CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,FALSE);
printf("Response Body:\n");
printf("%s\n",CkJsonObject_emit(jResp));
respStatusCode = CkHttpResponse_getStatusCode(resp);
printf("Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
printf("Response Header:\n");
printf("%s\n",CkHttpResponse_header(resp));
printf("Failed.\n");
CkHttpResponse_Dispose(resp);
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
return;
}
CkHttpResponse_Dispose(resp);
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "balance": {
// "amount": 127.43,
// "currency": "usd"
// }
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
Amount = CkJsonObject_stringOf(jResp,"balance.amount");
v_Currency = CkJsonObject_stringOf(jResp,"balance.currency");
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
}
Curl Command
curl -X PUT
-H "API-Key: {{API_KEY}}"
-H "Content-Type: application/json"
-d '{
"amount": 100,
"currency": "usd"
}'
https://api.shipengine.com/v1/carriers/se-963358/add_funds
Postman Collection Item JSON
{
"name": "Add funds to a carrier",
"request": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"amount\": 100,\n\t\"currency\": \"usd\"\n}"
},
"url": {
"raw": "https://api.shipengine.com/v1/carriers/{{stamps_com}}/add_funds",
"protocol": "https",
"host": [
"api",
"shipengine",
"com"
],
"path": [
"v1",
"carriers",
"{{stamps_com}}",
"add_funds"
]
},
"description": "You can check your balance for a particular carrier by calling List Carriers endpoint. For any carrier account where `requires_funded_amount` is true, you can add funds.\n\n> **NOTE:** This endpoint must be enabled by ShipEngine support, if you'd like to utilize this resource, please contact our team."
},
"response": [
{
"name": "Add funds to a carrier",
"originalRequest": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"amount\": 100,\n\t\"currency\": \"usd\"\n}"
},
"url": {
"raw": "https://api.shipengine.com/v1/carriers/{{stamps_com}}/add_funds",
"protocol": "https",
"host": [
"api",
"shipengine",
"com"
],
"path": [
"v1",
"carriers",
"{{stamps_com}}",
"add_funds"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Date",
"value": "Tue, 17 Sep 2019 15:14:01 GMT"
},
{
"key": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"key": "Content-Length",
"value": "307"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "Access-Control-Allow-Origin",
"value": "https://www.shipengine.com"
},
{
"key": "Vary",
"value": "Origin"
},
{
"key": "x-shipengine-requestid",
"value": "38af433e-6dee-41d8-b064-312e636760fe"
}
],
"cookie": [
],
"body": "{\n \"balance\": {\n \t\"amount\": 127.43,\n \t\"currency\": \"usd\"\n }\n}"
}
]
}