Chilkat Online Tools

Swift / Booking Management API v2021.12 / 3. 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 11",
    //       "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",
    //       "passengerCode": "ADT"
    //     }
    //   ],
    //   "contactInfo": {
    //     "emails": [
    //       "travel@sabre.com",
    //       "travel2@sabre.com"
    //     ],
    //     "phones": [
    //       "+123456"
    //     ]
    //   },
    //   "car": {
    //     "bookingKey": "{{carBookingKey}}"
    //   },
    //   "payment": {
    //     "formsOfPayment": [
    //       {
    //         "type": "PAYMENTCARD",
    //         "cardTypeCode": "VI",
    //         "cardNumber": "4487971000000006",
    //         "cardSecurityCode": "123",
    //         "expiryDate": "2022-10",
    //         "cardHolder": {
    //           "givenName": "John",
    //           "surname": "Smith",
    //           "email": "john@smith.family.priv",
    //           "phone": "+1-555-123-4567",
    //           "address": {
    //             "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 11")
    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].passengerCode", value: "ADT")
    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("car.bookingKey", value: "{{carBookingKey}}")
    json.UpdateString("payment.formsOfPayment[0].type", value: "PAYMENTCARD")
    json.UpdateString("payment.formsOfPayment[0].cardTypeCode", value: "VI")
    json.UpdateString("payment.formsOfPayment[0].cardNumber", value: "4487971000000006")
    json.UpdateString("payment.formsOfPayment[0].cardSecurityCode", value: "123")
    json.UpdateString("payment.formsOfPayment[0].expiryDate", value: "2022-10")
    json.UpdateString("payment.formsOfPayment[0].cardHolder.givenName", value: "John")
    json.UpdateString("payment.formsOfPayment[0].cardHolder.surname", value: "Smith")
    json.UpdateString("payment.formsOfPayment[0].cardHolder.email", value: "john@smith.family.priv")
    json.UpdateString("payment.formsOfPayment[0].cardHolder.phone", value: "+1-555-123-4567")
    json.UpdateString("payment.formsOfPayment[0].cardHolder.address.street", value: "1230 Ellen Ave, apt 10")
    json.UpdateString("payment.formsOfPayment[0].cardHolder.address.city", value: "Dallas")
    json.UpdateString("payment.formsOfPayment[0].cardHolder.address.stateProvince", value: "TX")
    json.UpdateString("payment.formsOfPayment[0].cardHolder.address.postalCode", value: "75063")
    json.UpdateString("payment.formsOfPayment[0].cardHolder.address.countryCode", value: "US")

    http.SetRequestHeader("accept", value: "application/json")
    http.SetRequestHeader("x-request-id", value: "dnjas82bd102bd912requestid")
    http.SetRequestHeader("X-Sabre-Group", value: "G7RE")
    http.SetRequestHeader("X-Sabre-Current-City", value: "G7RE")
    http.SetRequestHeader("ConversationId", value: "dnjas82bd102bd912conversationid")
    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 "accept: application/json"
	-H "Content-Type: application/json"
	-H "X-Sabre-Group: G7RE"
	-H "X-Sabre-Current-City: G7RE"
	-H "x-request-id: dnjas82bd102bd912requestid"
	-H "ConversationId: dnjas82bd102bd912conversationid"
	-d '{
  "agency": {
    "address": {
      "name": "John Smith",
      "street": "1230 Ellen Ave, apt 11",
      "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",
      "passengerCode": "ADT"
    }
  ],
  "contactInfo": {
    "emails": [
      "travel@sabre.com",
      "travel2@sabre.com"
    ],
    "phones": [
      "+123456"
    ]
  },
  "car": {
    "bookingKey": "{{carBookingKey}}"
  },
  "payment": {
    "formsOfPayment": [
      {
        "type": "PAYMENTCARD",
        "cardTypeCode": "VI",
        "cardNumber": "4487971000000006",
        "cardSecurityCode": "123",
        "expiryDate": "2022-10",
        "cardHolder": {
          "givenName": "John",
          "surname": "Smith",
          "email": "john@smith.family.priv",
          "phone": "+1-555-123-4567",
          "address": {
            "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": "3. createBooking",
  "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",
          "});\r",
          "\r",
          "pm.test(\"passed and returned values of x-request-id and ConversationId must be equal\", function () {\r",
          "    pm.expect(pm.response.headers.get('x-request-id')).to.eql('dnjas82bd102bd912requestid');\r",
          "    pm.expect(pm.response.headers.get('ConversationId')).to.eql('dnjas82bd102bd912conversationid');\r",
          "\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"
      },
      {
        "key": "x-request-id",
        "value": "dnjas82bd102bd912requestid",
        "type": "text"
      },
      {
        "key": "ConversationId",
        "value": "dnjas82bd102bd912conversationid",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"agency\": {\n    \"address\": {\n      \"name\": \"John Smith\",\n      \"street\": \"1230 Ellen Ave, apt 11\",\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\": \"Kowalski\",\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  \"car\": {\n    \"bookingKey\": \"{{carBookingKey}}\"\n  },\n  \"payment\": {\n    \"formsOfPayment\": [\n      {\n        \"type\": \"PAYMENTCARD\",\n        \"cardTypeCode\": \"VI\",\n        \"cardNumber\": \"4487971000000006\",\n        \"cardSecurityCode\": \"123\",\n        \"expiryDate\": \"2022-10\",\n        \"cardHolder\": {\n          \"givenName\": \"John\",\n          \"surname\": \"Smith\",\n          \"email\": \"john@smith.family.priv\",\n          \"phone\": \"+1-555-123-4567\",\n          \"address\": {\n            \"street\": \"1230 Ellen Ave, apt 10\",\n            \"city\": \"Dallas\",\n            \"stateProvince\": \"TX\",\n            \"postalCode\": \"75063\",\n            \"countryCode\": \"US\"\n          }\n        }\n      }\n    ]\n  }\n}"
    },
    "url": {
      "raw": "{{rest_endpoint}}/v1/trip/orders/createBooking",
      "host": [
        "{{rest_endpoint}}"
      ],
      "path": [
        "v1",
        "trip",
        "orders",
        "createBooking"
      ]
    },
    "description": "### <br>"
  },
  "response": [
  ]
}