Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkJsonObject json;
HCkHttpResponse resp;
// 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.
// {
// "agency": {
// "address": {
// "name": "John Smith",
// "street": "1230 Ellen Ave, apt 10",
// "city": "Dallas",
// "stateProvince": "TX",
// "postalCode": "75063",
// "countryCode": "US",
// "freeText": "John Smith\n1230 Ellen Ave, apt 10\nDallas, TX 75063\nUS"
// },
// "agencyCustomerNumber": "1234567",
// "ticketingPolicy": "TODAY"
// },
// "travelers": [
// {
// "givenName": "John",
// "surname": "Smith",
// "birthDate": "1970-01-23",
// "passengerCode": "ADT",
// "ancillaries": [
// {
// "reasonForIssuanceCode": "C",
// "electronicMiscellaneousDocumentType": "FLIGHT_COUPON_ASSOCIATED",
// "reasonForIssuanceName": "BAGGAGE",
// "subcode": "0CC",
// "airlineCode": "LH",
// "groupCode": "BG",
// "basePrice": "35.00",
// "currencyCode": "USD",
// "flightIndices": [
// 1
// ]
// }
// ],
// "specialServices": [
// {
// "code": "FBAG"
// }
// ]
// },
// {
// "givenName": "Mary",
// "surname": "Smith",
// "birthDate": "1970-01-23",
// "passengerCode": "ADT"
// }
// ],
// "contactInfo": {
// "emails": [
// "travel@sabre.com",
// "travel2@sabre.com"
// ],
// "phones": [
// "+123456"
// ]
// },
// "flightDetails": {
// "flights": [
// {
// "flightNumber": 809,
// "airlineCode": "LH",
// "fromAirportCode": "ARN",
// "toAirportCode": "FRA",
// "departureDate": "2021-11-20",
// "departureTime": "06:15",
// "bookingClass": "Y",
// "flightStatusCode": "NN"
// }
// ],
// "flightPricing": [
// {}
// ]
// },
// "payment": {
// "billingAddress": {
// "name": "John Smith",
// "street": "1230 Ellen Ave, apt 10",
// "city": "Dallas",
// "stateProvince": "TX",
// "postalCode": "75063",
// "countryCode": "US"
// }
// }
// }
json = CkJsonObject_Create();
CkJsonObject_UpdateString(json,"agency.address.name","John Smith");
CkJsonObject_UpdateString(json,"agency.address.street","1230 Ellen Ave, apt 10");
CkJsonObject_UpdateString(json,"agency.address.city","Dallas");
CkJsonObject_UpdateString(json,"agency.address.stateProvince","TX");
CkJsonObject_UpdateString(json,"agency.address.postalCode","75063");
CkJsonObject_UpdateString(json,"agency.address.countryCode","US");
CkJsonObject_UpdateString(json,"agency.address.freeText","John Smith\n1230 Ellen Ave, apt 10\nDallas, TX 75063\nUS");
CkJsonObject_UpdateString(json,"agency.agencyCustomerNumber","1234567");
CkJsonObject_UpdateString(json,"agency.ticketingPolicy","TODAY");
CkJsonObject_UpdateString(json,"travelers[0].givenName","John");
CkJsonObject_UpdateString(json,"travelers[0].surname","Smith");
CkJsonObject_UpdateString(json,"travelers[0].birthDate","1970-01-23");
CkJsonObject_UpdateString(json,"travelers[0].passengerCode","ADT");
CkJsonObject_UpdateString(json,"travelers[0].ancillaries[0].reasonForIssuanceCode","C");
CkJsonObject_UpdateString(json,"travelers[0].ancillaries[0].electronicMiscellaneousDocumentType","FLIGHT_COUPON_ASSOCIATED");
CkJsonObject_UpdateString(json,"travelers[0].ancillaries[0].reasonForIssuanceName","BAGGAGE");
CkJsonObject_UpdateString(json,"travelers[0].ancillaries[0].subcode","0CC");
CkJsonObject_UpdateString(json,"travelers[0].ancillaries[0].airlineCode","LH");
CkJsonObject_UpdateString(json,"travelers[0].ancillaries[0].groupCode","BG");
CkJsonObject_UpdateString(json,"travelers[0].ancillaries[0].basePrice","35.00");
CkJsonObject_UpdateString(json,"travelers[0].ancillaries[0].currencyCode","USD");
CkJsonObject_UpdateInt(json,"travelers[0].ancillaries[0].flightIndices[0]",1);
CkJsonObject_UpdateString(json,"travelers[0].specialServices[0].code","FBAG");
CkJsonObject_UpdateString(json,"travelers[1].givenName","Mary");
CkJsonObject_UpdateString(json,"travelers[1].surname","Smith");
CkJsonObject_UpdateString(json,"travelers[1].birthDate","1970-01-23");
CkJsonObject_UpdateString(json,"travelers[1].passengerCode","ADT");
CkJsonObject_UpdateString(json,"contactInfo.emails[0]","travel@sabre.com");
CkJsonObject_UpdateString(json,"contactInfo.emails[1]","travel2@sabre.com");
CkJsonObject_UpdateString(json,"contactInfo.phones[0]","+123456");
CkJsonObject_UpdateInt(json,"flightDetails.flights[0].flightNumber",809);
CkJsonObject_UpdateString(json,"flightDetails.flights[0].airlineCode","LH");
CkJsonObject_UpdateString(json,"flightDetails.flights[0].fromAirportCode","ARN");
CkJsonObject_UpdateString(json,"flightDetails.flights[0].toAirportCode","FRA");
CkJsonObject_UpdateString(json,"flightDetails.flights[0].departureDate","2021-11-20");
CkJsonObject_UpdateString(json,"flightDetails.flights[0].departureTime","06:15");
CkJsonObject_UpdateString(json,"flightDetails.flights[0].bookingClass","Y");
CkJsonObject_UpdateString(json,"flightDetails.flights[0].flightStatusCode","NN");
CkJsonObject_UpdateString(json,"payment.billingAddress.name","John Smith");
CkJsonObject_UpdateString(json,"payment.billingAddress.street","1230 Ellen Ave, apt 10");
CkJsonObject_UpdateString(json,"payment.billingAddress.city","Dallas");
CkJsonObject_UpdateString(json,"payment.billingAddress.stateProvince","TX");
CkJsonObject_UpdateString(json,"payment.billingAddress.postalCode","75063");
CkJsonObject_UpdateString(json,"payment.billingAddress.countryCode","US");
CkHttp_SetRequestHeader(http,"accept","application/json");
CkHttp_SetRequestHeader(http,"Content-Type","application/json");
CkHttp_SetRequestHeader(http,"X-Sabre-Group","G7RE");
// Adds the "Authorization: Bearer <access_token>" header.
CkHttp_putAuthToken(http,"<access_token>");
CkHttp_SetRequestHeader(http,"X-Sabre-Current-City","G7RE");
resp = CkHttp_PostJson3(http,"https://domain.com/","application/json",json);
if (CkHttp_getLastMethodSuccess(http) == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
return;
}
printf("%d\n",CkHttpResponse_getStatusCode(resp));
printf("%s\n",CkHttpResponse_bodyStr(resp));
CkHttpResponse_Dispose(resp);
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
}
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-H "accept: application/json"
-H "Content-Type: application/json"
-H "X-Sabre-Group: G7RE"
-H "X-Sabre-Current-City: G7RE"
-d '{
"agency": {
"address": {
"name": "John Smith",
"street": "1230 Ellen Ave, apt 10",
"city": "Dallas",
"stateProvince": "TX",
"postalCode": "75063",
"countryCode": "US",
"freeText": "John Smith\n1230 Ellen Ave, apt 10\nDallas, TX 75063\nUS"
},
"agencyCustomerNumber": "1234567",
"ticketingPolicy": "TODAY"
},
"travelers": [
{
"givenName": "John",
"surname": "Smith",
"birthDate": "1970-01-23",
"passengerCode": "ADT",
"ancillaries": [
{
"reasonForIssuanceCode": "C",
"electronicMiscellaneousDocumentType": "FLIGHT_COUPON_ASSOCIATED",
"reasonForIssuanceName": "BAGGAGE",
"subcode": "0CC",
"airlineCode": "LH",
"groupCode": "BG",
"basePrice": "35.00",
"currencyCode": "USD",
"flightIndices": [
1
]
}
],
"specialServices": [
{
"code": "FBAG"
}
]
},
{
"givenName": "Mary",
"surname": "Smith",
"birthDate": "1970-01-23",
"passengerCode": "ADT"
}
],
"contactInfo": {
"emails": [
"travel@sabre.com",
"travel2@sabre.com"
],
"phones": [
"+123456"
]
},
"flightDetails": {
"flights": [
{
"flightNumber": 809,
"airlineCode": "LH",
"fromAirportCode": "ARN",
"toAirportCode": "FRA",
"departureDate": "2021-11-20",
"departureTime": "06:15",
"bookingClass": "Y",
"flightStatusCode": "NN"
}
],
"flightPricing": [
{}
]
},
"payment": {
"billingAddress": {
"name": "John Smith",
"street": "1230 Ellen Ave, apt 10",
"city": "Dallas",
"stateProvince": "TX",
"postalCode": "75063",
"countryCode": "US"
}
}
}'
https://domain.com/
Postman Collection Item JSON
{
"name": "createBooking - Ancillaries baggage with SSR",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"response is ok\", function () {\r",
" pm.response.to.be.ok;\r",
" pm.response.to.have.status(200);\r",
"});\r",
"\r",
"pm.test(\"response must be valid and have a body\", function () {\r",
" // this assertion also checks if a body exists\r",
" pm.response.to.be.json; \r",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "accept",
"type": "text",
"value": "application/json"
},
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json"
},
{
"key": "X-Sabre-Group",
"value": "G7RE",
"type": "text"
},
{
"key": "X-Sabre-Current-City",
"value": "G7RE",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"agency\": {\n \"address\": {\n \"name\": \"John Smith\",\n \"street\": \"1230 Ellen Ave, apt 10\",\n \"city\": \"Dallas\",\n \"stateProvince\": \"TX\",\n \"postalCode\": \"75063\",\n \"countryCode\": \"US\",\n \"freeText\": \"John Smith\\n1230 Ellen Ave, apt 10\\nDallas, TX 75063\\nUS\"\n },\n \"agencyCustomerNumber\": \"1234567\",\n \"ticketingPolicy\": \"TODAY\"\n },\n \"travelers\": [\n {\n \"givenName\": \"John\",\n \"surname\": \"Smith\",\n \"birthDate\": \"1970-01-23\",\n \"passengerCode\": \"ADT\",\n \"ancillaries\": [\n {\n \"reasonForIssuanceCode\": \"C\",\n \"electronicMiscellaneousDocumentType\": \"FLIGHT_COUPON_ASSOCIATED\",\n \"reasonForIssuanceName\": \"BAGGAGE\",\n \"subcode\": \"0CC\",\n \"airlineCode\": \"LH\",\n \"groupCode\": \"BG\",\n \"basePrice\": \"35.00\",\n \"currencyCode\": \"USD\",\n \"flightIndices\": [\n 1\n ]\n }\n ],\n \"specialServices\": [\n {\n \"code\": \"FBAG\"\n }\n ]\n },\n {\n \"givenName\": \"Mary\",\n \"surname\": \"Smith\",\n \"birthDate\": \"1970-01-23\",\n \"passengerCode\": \"ADT\"\n }\n ],\n \"contactInfo\": {\n \"emails\": [\n \"travel@sabre.com\",\n \"travel2@sabre.com\"\n ],\n \"phones\": [\n \"+123456\"\n ]\n },\n \"flightDetails\": {\n \"flights\": [\n {\n \"flightNumber\": 809,\n \"airlineCode\": \"LH\",\n \"fromAirportCode\": \"ARN\",\n \"toAirportCode\": \"FRA\",\n \"departureDate\": \"2021-11-20\",\n \"departureTime\": \"06:15\",\n \"bookingClass\": \"Y\",\n \"flightStatusCode\": \"NN\"\n }\n ],\n \"flightPricing\": [\n {}\n ]\n },\n \"payment\": {\n \"billingAddress\": {\n \"name\": \"John Smith\",\n \"street\": \"1230 Ellen Ave, apt 10\",\n \"city\": \"Dallas\",\n \"stateProvince\": \"TX\",\n \"postalCode\": \"75063\",\n \"countryCode\": \"US\"\n }\n }\n}"
},
"url": {
"raw": "{{createBooking_endpoint}}",
"host": [
"{{createBooking_endpoint}}"
]
},
"description": "### <br>"
},
"response": [
]
}