Chilkat Online Tools

Swift / Booking Management API v2021.12 / 2. createBooking

Back to Collection Items

func chilkatTest() {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let http = CkoHttp()
    var success: Bool

    // 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": "Kowalski",
    //       "birthDate": "1970-01-23",
    //       "passengerCode": "ADT",
    //       "identityDocuments": [
    //         {
    //           "documentNumber": "0123456789",
    //           "documentType": "PASSPORT",
    //           "expiryDate": "2024-07-09",
    //           "issuingCountryCode": "US",
    //           "residenceCountryCode": "US",
    //           "givenName": "John",
    //           "middleName": "Jack",
    //           "surname": "Kowalski",
    //           "birthDate": "1980-12-02",
    //           "gender": "MALE"
    //         }
    //       ]
    //     },
    //     {
    //       "givenName": "All",
    //       "surname": "Kowalski",
    //       "birthDate": "2000-01-23",
    //       "passengerCode": "ADT",
    //       "identityDocuments": [
    //         {
    //           "documentNumber": "01234567890",
    //           "documentType": "PASSPORT",
    //           "expiryDate": "2024-07-09",
    //           "issuingCountryCode": "US",
    //           "residenceCountryCode": "US",
    //           "givenName": "All",
    //           "middleName": "Jack",
    //           "surname": "Kowalski",
    //           "birthDate": "1980-12-02",
    //           "gender": "MALE"
    //         }
    //       ]
    //     }
    //   ],
    //   "contactInfo": {
    //     "emails": [
    //       "travel@sabre.com",
    //       "travel2@sabre.com"
    //     ],
    //     "phones": [
    //       "+123456"
    //     ]
    //   },
    //   "flightDetails": {
    //     "flights": [
    //       {
    //         "flightNumber": "{{oFlightNumber}}",
    //         "airlineCode": "{{oMarketingAirline}}",
    //         "fromAirportCode": "{{oDepartureAirport}}",
    //         "toAirportCode": "{{oArrivalAirport}}",
    //         "departureDate": "{{start_date}}",
    //         "departureTime": "{{oDepartureTime}}",
    //         "bookingClass": "Y",
    //         "marriageGroup": false,
    //         "flightStatusCode": "NN"
    //       }
    //     ],
    //     "flightPricing": [
    //       {}
    //     ]
    //   },
    //   "payment": {
    //     "billingAddress": {
    //       "name": "John Smith",
    //       "street": "1230 Ellen Ave, apt 10",
    //       "city": "Dallas",
    //       "stateProvince": "TX",
    //       "postalCode": "75063",
    //       "countryCode": "US"
    //     }
    //   }
    // }

    let json = CkoJsonObject()
    json.UpdateString("agency.address.name", value: "John Smith")
    json.UpdateString("agency.address.street", value: "1230 Ellen Ave, apt 10")
    json.UpdateString("agency.address.city", value: "Dallas")
    json.UpdateString("agency.address.stateProvince", value: "TX")
    json.UpdateString("agency.address.postalCode", value: "75063")
    json.UpdateString("agency.address.countryCode", value: "US")
    json.UpdateString("agency.address.freeText", value: "John Smith\n1230 Ellen Ave, apt 10\nDallas, TX 75063\nUS")
    json.UpdateString("agency.agencyCustomerNumber", value: "1234567")
    json.UpdateString("agency.ticketingPolicy", value: "TODAY")
    json.UpdateString("travelers[0].givenName", value: "John")
    json.UpdateString("travelers[0].surname", value: "Kowalski")
    json.UpdateString("travelers[0].birthDate", value: "1970-01-23")
    json.UpdateString("travelers[0].passengerCode", value: "ADT")
    json.UpdateString("travelers[0].identityDocuments[0].documentNumber", value: "0123456789")
    json.UpdateString("travelers[0].identityDocuments[0].documentType", value: "PASSPORT")
    json.UpdateString("travelers[0].identityDocuments[0].expiryDate", value: "2024-07-09")
    json.UpdateString("travelers[0].identityDocuments[0].issuingCountryCode", value: "US")
    json.UpdateString("travelers[0].identityDocuments[0].residenceCountryCode", value: "US")
    json.UpdateString("travelers[0].identityDocuments[0].givenName", value: "John")
    json.UpdateString("travelers[0].identityDocuments[0].middleName", value: "Jack")
    json.UpdateString("travelers[0].identityDocuments[0].surname", value: "Kowalski")
    json.UpdateString("travelers[0].identityDocuments[0].birthDate", value: "1980-12-02")
    json.UpdateString("travelers[0].identityDocuments[0].gender", value: "MALE")
    json.UpdateString("travelers[1].givenName", value: "All")
    json.UpdateString("travelers[1].surname", value: "Kowalski")
    json.UpdateString("travelers[1].birthDate", value: "2000-01-23")
    json.UpdateString("travelers[1].passengerCode", value: "ADT")
    json.UpdateString("travelers[1].identityDocuments[0].documentNumber", value: "01234567890")
    json.UpdateString("travelers[1].identityDocuments[0].documentType", value: "PASSPORT")
    json.UpdateString("travelers[1].identityDocuments[0].expiryDate", value: "2024-07-09")
    json.UpdateString("travelers[1].identityDocuments[0].issuingCountryCode", value: "US")
    json.UpdateString("travelers[1].identityDocuments[0].residenceCountryCode", value: "US")
    json.UpdateString("travelers[1].identityDocuments[0].givenName", value: "All")
    json.UpdateString("travelers[1].identityDocuments[0].middleName", value: "Jack")
    json.UpdateString("travelers[1].identityDocuments[0].surname", value: "Kowalski")
    json.UpdateString("travelers[1].identityDocuments[0].birthDate", value: "1980-12-02")
    json.UpdateString("travelers[1].identityDocuments[0].gender", value: "MALE")
    json.UpdateString("contactInfo.emails[0]", value: "travel@sabre.com")
    json.UpdateString("contactInfo.emails[1]", value: "travel2@sabre.com")
    json.UpdateString("contactInfo.phones[0]", value: "+123456")
    json.UpdateString("flightDetails.flights[0].flightNumber", value: "{{oFlightNumber}}")
    json.UpdateString("flightDetails.flights[0].airlineCode", value: "{{oMarketingAirline}}")
    json.UpdateString("flightDetails.flights[0].fromAirportCode", value: "{{oDepartureAirport}}")
    json.UpdateString("flightDetails.flights[0].toAirportCode", value: "{{oArrivalAirport}}")
    json.UpdateString("flightDetails.flights[0].departureDate", value: "{{start_date}}")
    json.UpdateString("flightDetails.flights[0].departureTime", value: "{{oDepartureTime}}")
    json.UpdateString("flightDetails.flights[0].bookingClass", value: "Y")
    json.UpdateBool("flightDetails.flights[0].marriageGroup", value: false)
    json.UpdateString("flightDetails.flights[0].flightStatusCode", value: "NN")
    json.UpdateString("payment.billingAddress.name", value: "John Smith")
    json.UpdateString("payment.billingAddress.street", value: "1230 Ellen Ave, apt 10")
    json.UpdateString("payment.billingAddress.city", value: "Dallas")
    json.UpdateString("payment.billingAddress.stateProvince", value: "TX")
    json.UpdateString("payment.billingAddress.postalCode", value: "75063")
    json.UpdateString("payment.billingAddress.countryCode", value: "US")

    http.SetRequestHeader("Conversation-ID", value: "{{conv_id}}")
    http.SetRequestHeader("Content-Type", value: "application/json")
    // Adds the "Authorization: Bearer <access_token>" header.
    http.AuthToken = "<access_token>"

    var resp: CkoHttpResponse? = http.PostJson3("https://domain.com/v1/trip/orders/createBooking", contentType: "application/json", json: json)
    if http.LastMethodSuccess == false {
        print("\(http.LastErrorText)")
        return
    }

    print("\(resp!.StatusCode.intValue)")
    print("\(resp!.BodyStr)")
    resp = nil

}

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-H "Conversation-ID: {{conv_id}}"
	-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": "Kowalski",
			"birthDate": "1970-01-23",
			"passengerCode": "ADT",
            "identityDocuments": [
            {
                "documentNumber": "0123456789",
                "documentType": "PASSPORT",
                "expiryDate": "2024-07-09",
                "issuingCountryCode": "US",
                "residenceCountryCode": "US",
                "givenName": "John",
                "middleName": "Jack",
                "surname": "Kowalski",
                "birthDate": "1980-12-02",
                "gender": "MALE"
            }
            ]
		},
        {
			"givenName": "All",
			"surname": "Kowalski",
			"birthDate": "2000-01-23",
			"passengerCode": "ADT",
            "identityDocuments": [
            {
                "documentNumber": "01234567890",
                "documentType": "PASSPORT",
                "expiryDate": "2024-07-09",
                "issuingCountryCode": "US",
                "residenceCountryCode": "US",
                "givenName": "All",
                "middleName": "Jack",
                "surname": "Kowalski",
                "birthDate": "1980-12-02",
                "gender": "MALE"
            }
            ]
		}
	],
	"contactInfo":
    {
      "emails": [
        "travel@sabre.com",
		"travel2@sabre.com"
      ],
      "phones": [
        "+123456"
      ]
    },
	"flightDetails": {
		"flights": [
			{
				"flightNumber": "{{oFlightNumber}}",
				"airlineCode": "{{oMarketingAirline}}",
				"fromAirportCode": "{{oDepartureAirport}}",
				"toAirportCode": "{{oArrivalAirport}}",
				"departureDate": "{{start_date}}",
				"departureTime": "{{oDepartureTime}}",
				"bookingClass": "Y",
				"marriageGroup": false,
				"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/v1/trip/orders/createBooking

Postman Collection Item JSON

{
  "name": "2. createBooking",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "type": "text",
        "value": "application/json"
      },
      {
        "key": "Conversation-ID",
        "type": "text",
        "value": "{{conv_id}}"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n\t \"agency\": {\n\t\t\"address\": {\n\t\t\t\"name\": \"John Smith\",\n\t\t\t\"street\": \"1230 Ellen Ave, apt 10\",\n\t\t\t\"city\": \"Dallas\",\n\t\t\t\"stateProvince\": \"TX\",\n\t\t\t\"postalCode\": \"75063\",\n\t\t\t\"countryCode\": \"US\",\n\t\t\t\"freeText\": \"John Smith\\n1230 Ellen Ave, apt 10\\nDallas, TX 75063\\nUS\"\n\t\t},\n\t\t\"agencyCustomerNumber\": \"1234567\",\n\t\t\"ticketingPolicy\": \"TODAY\"\n  \t},\n\t\"travelers\": [\n\t\t{\n\t\t\t\"givenName\": \"John\",\n\t\t\t\"surname\": \"Kowalski\",\n\t\t\t\"birthDate\": \"1970-01-23\",\n\t\t\t\"passengerCode\": \"ADT\",\n            \"identityDocuments\": [\n            {\n                \"documentNumber\": \"0123456789\",\n                \"documentType\": \"PASSPORT\",\n                \"expiryDate\": \"2024-07-09\",\n                \"issuingCountryCode\": \"US\",\n                \"residenceCountryCode\": \"US\",\n                \"givenName\": \"John\",\n                \"middleName\": \"Jack\",\n                \"surname\": \"Kowalski\",\n                \"birthDate\": \"1980-12-02\",\n                \"gender\": \"MALE\"\n            }\n            ]\n\t\t},\n        {\n\t\t\t\"givenName\": \"All\",\n\t\t\t\"surname\": \"Kowalski\",\n\t\t\t\"birthDate\": \"2000-01-23\",\n\t\t\t\"passengerCode\": \"ADT\",\n            \"identityDocuments\": [\n            {\n                \"documentNumber\": \"01234567890\",\n                \"documentType\": \"PASSPORT\",\n                \"expiryDate\": \"2024-07-09\",\n                \"issuingCountryCode\": \"US\",\n                \"residenceCountryCode\": \"US\",\n                \"givenName\": \"All\",\n                \"middleName\": \"Jack\",\n                \"surname\": \"Kowalski\",\n                \"birthDate\": \"1980-12-02\",\n                \"gender\": \"MALE\"\n            }\n            ]\n\t\t}\n\t],\n\t\"contactInfo\":\n    {\n      \"emails\": [\n        \"travel@sabre.com\",\n\t\t\"travel2@sabre.com\"\n      ],\n      \"phones\": [\n        \"+123456\"\n      ]\n    },\n\t\"flightDetails\": {\n\t\t\"flights\": [\n\t\t\t{\n\t\t\t\t\"flightNumber\": \"{{oFlightNumber}}\",\n\t\t\t\t\"airlineCode\": \"{{oMarketingAirline}}\",\n\t\t\t\t\"fromAirportCode\": \"{{oDepartureAirport}}\",\n\t\t\t\t\"toAirportCode\": \"{{oArrivalAirport}}\",\n\t\t\t\t\"departureDate\": \"{{start_date}}\",\n\t\t\t\t\"departureTime\": \"{{oDepartureTime}}\",\n\t\t\t\t\"bookingClass\": \"Y\",\n\t\t\t\t\"marriageGroup\": false,\n\t\t\t\t\"flightStatusCode\": \"NN\"\n\t\t\t}\n\t\t],\n        \"flightPricing\": [\n        {\n        }\n    ]\n\t},\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": "{{rest_endpoint}}/v1/trip/orders/createBooking",
      "host": [
        "{{rest_endpoint}}"
      ],
      "path": [
        "v1",
        "trip",
        "orders",
        "createBooking"
      ]
    },
    "description": "[//]: # \"Start\"\n\n<b>[Description](https://developer.sabre.com/docs/rest_apis/trip/orders/booking_management), [Resources](https://developer.sabre.com/docs/rest_apis/trip/orders/booking_management/reference-documentation), [Help](https://developer.sabre.com/docs/rest_apis/trip/orders/booking_management/help)</b>\n\n[//]: # \"End\""
  },
  "response": [
  ]
}