Unicode C
Unicode C
Shippo Create a New Manifest
See more Shippo Examples
Demonstrates how to create a manifest for your shipments.Chilkat Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
HCkJsonObjectW json;
HCkHttpResponseW resp;
HCkStringBuilderW sbResponseBody;
HCkJsonObjectW jResp;
int respStatusCode;
const wchar_t *strVal;
const wchar_t *address_from;
const wchar_t *carrier_account;
const wchar_t *object_created;
const wchar_t *object_id;
const wchar_t *object_owner;
const wchar_t *object_updated;
const wchar_t *shipment_date;
const wchar_t *status;
int i;
int count_i;
success = FALSE;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
// Implements the following CURL command:
// curl https://api.goshippo.com/manifests/
// -H "Authorization: ShippoToken shippo_test_831a7a042784f523b95db65444e6e084b636764b" \
// -H "Content-Type: application/json" \
// -d '{
// "carrier_account": "b741b99f95e841639b54272834bc478c",
// "shipment_date": "2014-05-16T23:59:59Z",
// "address_from": "28828839a2b04e208ac2aa4945fbca9a",
// "transactions": [
// "64bba01845ef40d29374032599f22588",
// "c169aa586a844cc49da00d0272b590e1"
// ],
// "async": false
// }'
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "carrier_account": "b741b99f95e841639b54272834bc478c",
// "shipment_date": "2014-05-16T23:59:59Z",
// "address_from": "28828839a2b04e208ac2aa4945fbca9a",
// "transactions": [
// "64bba01845ef40d29374032599f22588",
// "c169aa586a844cc49da00d0272b590e1"
// ],
// "async": false
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"carrier_account",L"b741b99f95e841639b54272834bc478c");
CkJsonObjectW_UpdateString(json,L"shipment_date",L"2014-05-16T23:59:59Z");
CkJsonObjectW_UpdateString(json,L"address_from",L"28828839a2b04e208ac2aa4945fbca9a");
CkJsonObjectW_UpdateString(json,L"transactions[0]",L"64bba01845ef40d29374032599f22588");
CkJsonObjectW_UpdateString(json,L"transactions[1]",L"c169aa586a844cc49da00d0272b590e1");
CkJsonObjectW_UpdateBool(json,L"async",FALSE);
CkHttpW_SetRequestHeader(http,L"Authorization",L"ShippoToken shippo_test_831a7a042784f523b95db65444e6e084b636764b");
CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
resp = CkHttpResponseW_Create();
success = CkHttpW_HttpJson(http,L"POST",L"https://api.goshippo.com/manifests/",json,L"application/json",resp);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkHttpResponseW_Dispose(resp);
return;
}
sbResponseBody = CkStringBuilderW_Create();
CkHttpResponseW_GetBodySb(resp,sbResponseBody);
jResp = CkJsonObjectW_Create();
CkJsonObjectW_LoadSb(jResp,sbResponseBody);
CkJsonObjectW_putEmitCompact(jResp,FALSE);
wprintf(L"Response Body:\n");
wprintf(L"%s\n",CkJsonObjectW_emit(jResp));
respStatusCode = CkHttpResponseW_getStatusCode(resp);
wprintf(L"Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",CkHttpResponseW_header(resp));
wprintf(L"Failed.\n");
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkHttpResponseW_Dispose(resp);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "address_from": "28828839a2b04e208ac2aa4945fbca9a",
// "carrier_account": "b741b99f95e841639b54272834bc478c",
// "documents": [
// "https://shippo-delivery.s3.amazonaws.com/0fadebf6f60c4aca95fa01bcc59c79ae.pdf?Signature=tlQU3RECwdHUQJQadwqg5bAzGFQ%3D&Expires=1402803835&AWSAccessKeyId=AKIAJTHP3LLFMYAWALIA"
// ],
// "object_created": "2014-05-16T03:43:52.765Z",
// "object_id": "0fadebf6f60c4aca95fa01bcc59c79ae",
// "object_owner": "mrhippo@goshippo.com",
// "object_updated": "2014-05-16T03:43:55.445Z",
// "shipment_date": "2014-05-16T23:59:59Z",
// "status": "SUCCESS",
// "transactions": [
// "64bba01845ef40d29374032599f22588",
// "c169aa586a844cc49da00d0272b590e1"
// ]
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
// See this example explaining how this memory should be used: const char * functions.
address_from = CkJsonObjectW_stringOf(jResp,L"address_from");
carrier_account = CkJsonObjectW_stringOf(jResp,L"carrier_account");
object_created = CkJsonObjectW_stringOf(jResp,L"object_created");
object_id = CkJsonObjectW_stringOf(jResp,L"object_id");
object_owner = CkJsonObjectW_stringOf(jResp,L"object_owner");
object_updated = CkJsonObjectW_stringOf(jResp,L"object_updated");
shipment_date = CkJsonObjectW_stringOf(jResp,L"shipment_date");
status = CkJsonObjectW_stringOf(jResp,L"status");
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"documents");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
strVal = CkJsonObjectW_stringOf(jResp,L"documents[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"transactions");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
strVal = CkJsonObjectW_stringOf(jResp,L"transactions[i]");
i = i + 1;
}
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkHttpResponseW_Dispose(resp);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
}