{
  "info": {
    "name": "WyseConnector API",
    "description": "Test collection for the WyseConnector API: one API for hotels and activities across suppliers.\n\n**Setup**\n1. Open the collection's *Variables* tab and paste your API key into `apiKey` (Current value).\n2. Check `baseUrl` and `currency` (your account currency).\n3. Run the requests in each folder in order. Each request saves the ids the next one needs, and dates are set automatically.\n\n**Rules**\n- Money is an integer in minor units: divide by 10^`decimals` (AED 16855 = AED 168.55).\n- `total = supplier_total + platform_fee + markup`. Your account is charged `supplier_total + platform_fee`.\n- Every booking needs an `Idempotency-Key`; the collection makes a new one per send.\n- Test bookings are not real. Cancel every booking you make.\n\nFull reference: {{baseUrl}}/docs/ · OpenAPI: {{baseUrl}}/docs/openapi.yaml",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{apiKey}}",
        "type": "string"
      }
    ]
  },
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "// Dates relative to today, so the collection never goes stale.",
          "const day = n => { const d = new Date(); d.setUTCDate(d.getUTCDate() + n); return d.toISOString().slice(0, 10); };",
          "pm.collectionVariables.set('checkin', day(30));",
          "pm.collectionVariables.set('checkout', day(32));",
          "pm.collectionVariables.set('actFrom', day(14));",
          "pm.collectionVariables.set('actTo', day(16));",
          "pm.request.headers.upsert({ key: 'X-Request-Id', value: 'postman-' + Date.now() });"
        ]
      }
    }
  ],
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://sandbox.wyseconnector.com",
      "type": "string"
    },
    {
      "key": "apiKey",
      "value": "",
      "type": "string"
    },
    {
      "key": "currency",
      "value": "USD",
      "type": "string"
    },
    {
      "key": "checkin",
      "value": "",
      "type": "string"
    },
    {
      "key": "checkout",
      "value": "",
      "type": "string"
    },
    {
      "key": "actFrom",
      "value": "",
      "type": "string"
    },
    {
      "key": "actTo",
      "value": "",
      "type": "string"
    },
    {
      "key": "searchId",
      "value": "",
      "type": "string"
    },
    {
      "key": "rateId",
      "value": "",
      "type": "string"
    },
    {
      "key": "hotelPrebookId",
      "value": "",
      "type": "string"
    },
    {
      "key": "hotelBookingId",
      "value": "",
      "type": "string"
    },
    {
      "key": "activityId",
      "value": "",
      "type": "string"
    },
    {
      "key": "optionId",
      "value": "",
      "type": "string"
    },
    {
      "key": "activityPrebookId",
      "value": "",
      "type": "string"
    },
    {
      "key": "activityQuestions",
      "value": "",
      "type": "string"
    },
    {
      "key": "activityPax",
      "value": "",
      "type": "string"
    },
    {
      "key": "activityAnswers",
      "value": "",
      "type": "string"
    },
    {
      "key": "activityBookingId",
      "value": "",
      "type": "string"
    },
    {
      "key": "idemKey",
      "value": "",
      "type": "string"
    }
  ],
  "item": [
    {
      "name": "0. Account",
      "description": "Check the key works, the wallet, and the suppliers on your account.",
      "item": [
        {
          "name": "Account balance",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 200', () => pm.expect(pm.response.code).to.be.oneOf([200]));",
                  "const b = pm.response.json();",
                  "pm.test('has a currency', () => pm.expect(b.currency).to.match(/^[A-Z]{3}$/));"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/v1/account",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "v1",
                "account"
              ]
            },
            "description": "Credit limit, balance, amount on hold and available credit, in your account currency. Money is in minor units: divide by 10^decimals (AED 500000 = AED 5,000.00)."
          }
        },
        {
          "name": "Account statement",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 200', () => pm.expect(pm.response.code).to.be.oneOf([200]));"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/v1/account/statement?limit=20",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "v1",
                "account",
                "statement"
              ],
              "query": [
                {
                  "key": "limit",
                  "value": "20"
                }
              ]
            },
            "description": "Charges, refunds and top-ups, newest first."
          }
        },
        {
          "name": "Suppliers on my account",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 200', () => pm.expect(pm.response.code).to.be.oneOf([200]));"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/v1/suppliers",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "v1",
                "suppliers"
              ]
            },
            "description": "The suppliers your account can sell, with the services each provides and its health."
          }
        }
      ]
    },
    {
      "name": "1. Hotels",
      "description": "Search, prebook, book and cancel hotels. On the test environment hotels come from the supplier's sandbox: book only the test hotel (step 3 onwards), and cancel every test booking.",
      "item": [
        {
          "name": "1. Destinations (autocomplete)",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 200', () => pm.expect(pm.response.code).to.be.oneOf([200]));"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/hotels/v1/destinations?q=dubai&limit=5",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "hotels",
                "v1",
                "destinations"
              ],
              "query": [
                {
                  "key": "q",
                  "value": "dubai"
                },
                {
                  "key": "limit",
                  "value": "5"
                }
              ]
            },
            "description": "Cities, hotels and landmarks matching the text. Pass a suggestion's `destination` unchanged into search."
          }
        },
        {
          "name": "2. Search hotels in Dubai",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 200', () => pm.expect(pm.response.code).to.be.oneOf([200]));",
                  "const b = pm.response.json();",
                  "pm.test('offers returned', () => pm.expect(b.offers.length).to.be.above(0));",
                  "if (b.search_id) pm.collectionVariables.set('searchId', b.search_id);"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/hotels/v1/search",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "hotels",
                "v1",
                "search"
              ]
            },
            "description": "Priced hotels across every supplier on your account. Dates are set automatically to 30 and 32 days from today. The response is a search session (`search_id`) you can filter and page for 20 minutes.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"checkin\": \"{{checkin}}\",\n  \"checkout\": \"{{checkout}}\",\n  \"rooms\": [\n    {\n      \"adults\": 2\n    }\n  ],\n  \"destination\": {\n    \"country_code\": \"AE\",\n    \"city_name\": \"Dubai\"\n  },\n  \"currency\": \"{{currency}}\",\n  \"guest_nationality\": \"IN\",\n  \"sort\": \"price_asc\",\n  \"page_size\": 20\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "2b. Refine: 4-5 stars, free cancellation",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 200', () => pm.expect(pm.response.code).to.be.oneOf([200]));"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/hotels/v1/searches/{{searchId}}?star_ratings=4,5&refundable_only=true&sort=price_asc&page=1&page_size=10",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "hotels",
                "v1",
                "searches",
                "{{searchId}}"
              ],
              "query": [
                {
                  "key": "star_ratings",
                  "value": "4,5"
                },
                {
                  "key": "refundable_only",
                  "value": "true"
                },
                {
                  "key": "sort",
                  "value": "price_asc"
                },
                {
                  "key": "page",
                  "value": "1"
                },
                {
                  "key": "page_size",
                  "value": "10"
                }
              ]
            },
            "description": "Filters, sorts and pages the search session without calling suppliers again."
          }
        },
        {
          "name": "3. Search the test hotel (for booking)",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 200', () => pm.expect(pm.response.code).to.be.oneOf([200]));",
                  "const b = pm.response.json();",
                  "const rate = b.offers && b.offers[0] && b.offers[0].rates[0];",
                  "pm.test('a rate to book', () => pm.expect(rate).to.be.ok);",
                  "if (rate) pm.collectionVariables.set('rateId', rate.id);"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/hotels/v1/search",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "hotels",
                "v1",
                "search"
              ]
            },
            "description": "The supplier's sandbox test hotel. Saves the first rate for the next step.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"checkin\": \"{{checkin}}\",\n  \"checkout\": \"{{checkout}}\",\n  \"rooms\": [\n    {\n      \"adults\": 2\n    }\n  ],\n  \"destination\": {\n    \"hotel_ids\": [\n      \"ratehawk~10004834\"\n    ]\n  },\n  \"currency\": \"{{currency}}\",\n  \"guest_nationality\": \"IN\",\n  \"max_rates_per_hotel\": 5\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "4. Hotel page",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 200', () => pm.expect(pm.response.code).to.be.oneOf([200]));"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/hotels/v1/hotels/ratehawk~10004834",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "hotels",
                "v1",
                "hotels",
                "ratehawk~10004834"
              ]
            },
            "description": "Photos, description, facilities, room types and policies."
          }
        },
        {
          "name": "5. Prebook the rate",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 201', () => pm.expect(pm.response.code).to.be.oneOf([201]));",
                  "const b = pm.response.json();",
                  "pm.collectionVariables.set('hotelPrebookId', b.id);",
                  "console.log('Hotel price', b.price.currency, b.price.total / Math.pow(10, b.price.decimals), 'charged to the account:', (b.price.supplier_total + b.price.platform_fee) / Math.pow(10, b.price.decimals));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/hotels/v1/prebooks",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "hotels",
                "v1",
                "prebooks"
              ]
            },
            "description": "The supplier confirms the price and conditions, valid 20 minutes. Show `cancellation`, `pay_at_property` and any change flag before booking.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"rate_id\": \"{{rateId}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "6. Book",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.collectionVariables.set('idemKey', 'postman-' + Date.now());"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 201 or 202', () => pm.expect(pm.response.code).to.be.oneOf([201, 202]));",
                  "const b = pm.response.json();",
                  "pm.collectionVariables.set('hotelBookingId', b.id);",
                  "console.log('Booking', b.id, b.status, b.supplier_booking_id);"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Idempotency-Key",
                "value": "{{idemKey}}"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/hotels/v1/bookings",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "hotels",
                "v1",
                "bookings"
              ]
            },
            "description": "Books the prebook. A new `Idempotency-Key` is made for every send; sending the same key again returns the same booking instead of booking twice. 201 = confirmed, 202 = outcome unknown (refresh, never rebook), 422 = failed.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"prebook_id\": \"{{hotelPrebookId}}\",\n  \"client_reference\": \"POSTMAN-TEST\",\n  \"holder\": {\n    \"first_name\": \"Test\",\n    \"last_name\": \"Traveller\",\n    \"email\": \"test@example.com\",\n    \"phone\": \"+971500000000\"\n  },\n  \"guests\": [\n    {\n      \"room_number\": 1,\n      \"first_name\": \"Test\",\n      \"last_name\": \"Traveller\"\n    }\n  ]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "7. Retrieve the booking",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 200', () => pm.expect(pm.response.code).to.be.oneOf([200]));"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/hotels/v1/bookings/{{hotelBookingId}}?refresh=true",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "hotels",
                "v1",
                "bookings",
                "{{hotelBookingId}}"
              ],
              "query": [
                {
                  "key": "refresh",
                  "value": "true"
                }
              ]
            },
            "description": "`refresh=true` re-reads the booking from the supplier."
          }
        },
        {
          "name": "8. List bookings",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 200', () => pm.expect(pm.response.code).to.be.oneOf([200]));"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/hotels/v1/bookings?page=1&page_size=10",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "hotels",
                "v1",
                "bookings"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "1"
                },
                {
                  "key": "page_size",
                  "value": "10"
                }
              ]
            },
            "description": ""
          }
        },
        {
          "name": "9. Cancellation quote",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 200', () => pm.expect(pm.response.code).to.be.oneOf([200]));"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/hotels/v1/bookings/{{hotelBookingId}}/cancellation-quote",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "hotels",
                "v1",
                "bookings",
                "{{hotelBookingId}}",
                "cancellation-quote"
              ]
            },
            "description": "Fee and refund if cancelled now. Show it before cancelling."
          }
        },
        {
          "name": "10. Cancel",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 200', () => pm.expect(pm.response.code).to.be.oneOf([200]));",
                  "const b = pm.response.json();",
                  "pm.test('cancelled', () => pm.expect(b.status).to.eql('cancelled'));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/hotels/v1/bookings/{{hotelBookingId}}/cancel",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "hotels",
                "v1",
                "bookings",
                "{{hotelBookingId}}",
                "cancel"
              ]
            },
            "description": "Cancels under the supplier's policy; the refund goes back to the account."
          }
        }
      ]
    },
    {
      "name": "2. Activities",
      "description": "Tours, attractions and tickets. Run the requests in order: each one saves the id the next one needs. On the test environment, activities exist in Dubai (1), Singapore (7) and Kota Kinabalu, Malaysia (1). Prices in another currency (SGD, MYR) are converted into your account currency; see `price.fx`.",
      "item": [
        {
          "name": "1. Search activities in Dubai",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 200', () => pm.expect(pm.response.code).to.be.oneOf([200]));",
                  "const b = pm.response.json();",
                  "pm.test('activities returned', () => pm.expect(b.offers.length).to.be.above(0));",
                  "if (b.offers.length) pm.collectionVariables.set('activityId', b.offers[0].id);",
                  "b.offers.forEach(o => console.log(o.activity.name, '-', o.from_price.currency, o.from_price.total / Math.pow(10, o.from_price.decimals)));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/activities/v1/search",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "activities",
                "v1",
                "search"
              ]
            },
            "description": "Activities with a 'from' price for the travellers over the dates (set automatically to 14-16 days from today). Saves the first activity.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"destination\": {\n    \"country_code\": \"AE\",\n    \"city_name\": \"Dubai\"\n  },\n  \"from\": \"{{actFrom}}\",\n  \"to\": \"{{actTo}}\",\n  \"travellers\": {\n    \"adults\": 2\n  },\n  \"currency\": \"{{currency}}\",\n  \"guest_nationality\": \"IN\",\n  \"language\": \"en\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "1b. Search activities in Singapore",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 200', () => pm.expect(pm.response.code).to.be.oneOf([200]));",
                  "const b = pm.response.json();",
                  "const bookable = b.offers.filter(o => !/formula/i.test(o.activity.name));",
                  "if (bookable.length) pm.collectionVariables.set('activityId', bookable[0].id);",
                  "b.offers.forEach(o => console.log(o.activity.name, '-', o.from_price.currency, o.from_price.total / Math.pow(10, o.from_price.decimals), o.from_price.fx ? '(from ' + o.from_price.fx.currency + ')' : ''));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/activities/v1/search",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "activities",
                "v1",
                "search"
              ]
            },
            "description": "The supplier prices Singapore in SGD; prices come back converted into the requested currency with the conversion on `from_price.fx`. Saves the cheapest activity (run this instead of 1 to book in Singapore).",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"destination\": {\n    \"country_code\": \"SG\",\n    \"city_name\": \"Singapore\"\n  },\n  \"from\": \"{{actFrom}}\",\n  \"to\": \"{{actTo}}\",\n  \"travellers\": {\n    \"adults\": 2,\n    \"children_ages\": [\n      8\n    ]\n  },\n  \"currency\": \"{{currency}}\",\n  \"guest_nationality\": \"IN\",\n  \"language\": \"en\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "2. Activity details",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 200', () => pm.expect(pm.response.code).to.be.oneOf([200]));"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/activities/v1/activities/{{activityId}}?language=en",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "activities",
                "v1",
                "activities",
                "{{activityId}}"
              ],
              "query": [
                {
                  "key": "language",
                  "value": "en"
                }
              ]
            },
            "description": "Description, photos, inclusions, meeting point and important information."
          }
        },
        {
          "name": "3. Availability (dates, times, prices)",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 200', () => pm.expect(pm.response.code).to.be.oneOf([200]));",
                  "const b = pm.response.json();",
                  "pm.test('options returned', () => pm.expect(b.options.length).to.be.above(0));",
                  "if (b.options.length) pm.collectionVariables.set('optionId', b.options[0].id);",
                  "b.options.slice(0, 10).forEach(o => console.log(o.date, o.start_time || '', o.name, '-', o.price.currency, o.price.total / Math.pow(10, o.price.decimals)));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/activities/v1/activities/{{activityId}}/availability",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "activities",
                "v1",
                "activities",
                "{{activityId}}",
                "availability"
              ]
            },
            "description": "Bookable options: one date and start time each, with the exact price for all travellers, cancellation terms and the questions to answer. Saves the first option.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"from\": \"{{actFrom}}\",\n  \"to\": \"{{actTo}}\",\n  \"travellers\": {\n    \"adults\": 2\n  },\n  \"currency\": \"{{currency}}\",\n  \"language\": \"en\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "4. Prebook the option",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 201', () => pm.expect(pm.response.code).to.be.oneOf([201]));",
                  "const b = pm.response.json();",
                  "pm.collectionVariables.set('activityPrebookId', b.id);",
                  "pm.collectionVariables.set('activityQuestions', JSON.stringify(b.questions || []));",
                  "pm.collectionVariables.set('activityPax', String(b.travellers.adults + (b.travellers.children_ages || []).length));",
                  "console.log('Price', b.price.currency, b.price.total / Math.pow(10, b.price.decimals), 'charged to the account:', (b.price.supplier_total + b.price.platform_fee) / Math.pow(10, b.price.decimals));",
                  "if (b.price.fx) console.log('Converted from', b.price.fx.currency, b.price.fx.supplier_total / Math.pow(10, b.price.fx.decimals), 'at', b.price.fx.rate, '+', b.price.fx.margin_bps / 100, '% FX margin');"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/activities/v1/prebooks",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "activities",
                "v1",
                "prebooks"
              ]
            },
            "description": "The supplier confirms the price, valid 20 minutes. Returns the questions to answer when booking and the terms to show the traveller.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"option_id\": \"{{optionId}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "5. Book",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// Answer the prebook's required questions with test values (per traveller where asked).",
                  "const qs = JSON.parse(pm.collectionVariables.get('activityQuestions') || '[]');",
                  "const pax = Number(pm.collectionVariables.get('activityPax') || 1);",
                  "const answers = [];",
                  "qs.filter(q => q.required).forEach(q => {",
                  "  if (q.per_pax) { for (let i = 1; i <= pax; i++) answers.push({ code: q.code, value: 'Test answer', pax_index: i }); }",
                  "  else answers.push({ code: q.code, value: 'Test answer' });",
                  "});",
                  "pm.collectionVariables.set('activityAnswers', JSON.stringify(answers));",
                  "pm.collectionVariables.set('idemKey', 'postman-' + Date.now());"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 201 or 202', () => pm.expect(pm.response.code).to.be.oneOf([201, 202]));",
                  "const b = pm.response.json();",
                  "pm.collectionVariables.set('activityBookingId', b.id);",
                  "console.log('Booking', b.id, b.status, 'supplier ref', b.supplier_booking_id, 'tickets', b.ticket_status);"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Idempotency-Key",
                "value": "{{idemKey}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/activities/v1/bookings",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "activities",
                "v1",
                "bookings"
              ]
            },
            "description": "Books the prebook and charges the account. Required questions are answered automatically with test values. A new `Idempotency-Key` is made for every send. 201 = confirmed, 202 = outcome unknown (refresh, never rebook), 422 = failed.",
            "body": {
              "mode": "raw",
              "options": {
                "raw": {
                  "language": "json"
                }
              },
              "raw": "{\n  \"prebook_id\": \"{{activityPrebookId}}\",\n  \"client_reference\": \"POSTMAN-TEST\",\n  \"holder\": { \"first_name\": \"Test\", \"last_name\": \"Traveller\", \"email\": \"test@example.com\", \"phone\": \"+971500000000\" },\n  \"answers\": {{activityAnswers}}\n}"
            }
          }
        },
        {
          "name": "6. Retrieve with tickets",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 200', () => pm.expect(pm.response.code).to.be.oneOf([200]));",
                  "const b = pm.response.json();",
                  "console.log('Tickets', b.ticket_status, JSON.stringify(b.tickets || []));"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/activities/v1/bookings/{{activityBookingId}}?refresh=true",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "activities",
                "v1",
                "bookings",
                "{{activityBookingId}}"
              ],
              "query": [
                {
                  "key": "refresh",
                  "value": "true"
                }
              ]
            },
            "description": "Asks the supplier for the latest status and tickets. If `ticket_status` is `pending`, send again in a minute."
          }
        },
        {
          "name": "7. List activity bookings",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 200', () => pm.expect(pm.response.code).to.be.oneOf([200]));"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/activities/v1/bookings?page=1&page_size=10",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "activities",
                "v1",
                "bookings"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "1"
                },
                {
                  "key": "page_size",
                  "value": "10"
                }
              ]
            },
            "description": ""
          }
        },
        {
          "name": "8. Cancel",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('HTTP 200', () => pm.expect(pm.response.code).to.be.oneOf([200]));",
                  "const b = pm.response.json();",
                  "pm.test('cancelled', () => pm.expect(b.status).to.eql('cancelled'));",
                  "if (b.account_charge) console.log('Refunded', b.account_charge.currency, (b.account_charge.refunded || 0) / 100);"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/activities/v1/bookings/{{activityBookingId}}/cancel",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "activities",
                "v1",
                "bookings",
                "{{activityBookingId}}",
                "cancel"
              ]
            },
            "description": "Cancels the booking; the supplier's refund goes back to the account (converted at the booking's rate when the supplier priced in another currency)."
          }
        }
      ]
    }
  ]
}
