### Python Access Token Management Example Setup Source: https://open-api-docs.guesty.com/recipes/access-token-management This Python script outlines the setup for managing access tokens using client credentials. It includes importing necessary libraries and defining basic configuration for token requests and caching. ```python """ Guesty Open API API Token Management Example This Python script demonstrates how to: - Request an access token using client credentials - Cache the token locally to avoid unnecessary renewals - Reuse the token in subsequent API requests - Refresh the token 5 minutes before it expires Prerequisites: - Python 3.6+ installed - requests package installed (pip install requests) - Your Guesty Open API Client ID and Client Secret """ import os import json import time import requests from datetime import datetime ``` -------------------------------- ### cURL Request Example Source: https://open-api-docs.guesty.com/reference-link/reservationsopenapicontroller_getreservationsbyids Demonstrates how to make a GET request to retrieve reservations using cURL. Includes common query parameters for filtering and response customization. ```shell curl --request GET \ --url 'https://open-api.guesty.com/v1/reservations-v3?includePaymentsTemplate=false&mergeAccommodationFarePriceComponents=false' \ --header 'accept: application/json' ``` -------------------------------- ### GET Listings using Access Token Source: https://open-api-docs.guesty.com/docs/migrating-to-the-guesty-open-api Example of how to make a GET request to retrieve listings from Guesty's Open API. Ensure you include your obtained Access Token in the Authorization header. ```shell curl --location --request GET 'https://open-api.guesty.com/v1/listings' \ --header 'accept: application/json' \ --header 'Authorization: Bearer {access_token}' ``` -------------------------------- ### Query Listing Availability with Python http.client Source: https://open-api-docs.guesty.com/docs/available-listings This Python example uses the `http.client` library to query listing availability. It sets up the connection, headers, and makes a GET request. Substitute `{accessToken}` with your token. ```python import http.client conn = http.client.HTTPSConnection("open-api.guesty.com") payload = '' headers = { 'Accept': 'application/json', 'authorization': '{accessToken}' } conn.request("GET", "/v1/listings?ids=62ec6975134d780032b62221&city=Sydney&fields=_id%20nickname%20title%20type%20address%20terms%20prices&available=%7B%22checkIn%22:%222023-09-01%22,%22checkOut%22:%222023-09-10%22,%22minOccupancy%22:2%7D", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8")) ``` -------------------------------- ### Query Listings by City and Availability (Python) Source: https://open-api-docs.guesty.com/docs/available-listings This Python example demonstrates how to query the Guesty API using the http.client library. It sends a GET request with specified headers and URL parameters for filtering listings. ```python import http.client conn = http.client.HTTPSConnection("open-api.guesty.com") payload = '' headers = { 'Accept': 'application/json', 'authorization': '{accessToken}' } conn.request("GET", "/v1/listings?city=Sydney&fields=_id%20nickname%20title%20type%20address%20terms%20prices&available=%7B%22checkIn%22:%222023-09-01%22,%22checkOut%22:%222023-09-10%22,%22minOccupancy%22:2%7D", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8")) ``` -------------------------------- ### Retrieve All Reservations (Python) Source: https://open-api-docs.guesty.com/docs/how-to-search-for-reservations This Python example uses the http.client library to make a GET request for all reservations. It sets the Authorization header and prints the response. Ensure you replace {token} with your API key. ```python import http.client conn = http.client.HTTPSConnection("open-api.guesty.com") payload = '' headers = { 'Authorization': 'Bearer {token}', } conn.request("GET", "/v1/reservations?filters=%5B%5D&skip=0&limit=100&sort=_id", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8")) ``` -------------------------------- ### Search Reservations with Python HTTP Client Source: https://open-api-docs.guesty.com/docs/how-to-search-for-reservations This Python example utilizes the 'http.client' library to make a GET request to the Guesty API. It shows how to establish a connection and send the request with authorization headers. ```python import http.client conn = http.client.HTTPSConnection("open-api.guesty.com") payload = '' headers = { 'Authorization': 'Bearer {token}' } conn.request("GET", "/v1/reservations?fields=_id%20confirmationCode%20status%20checkInDateLocalized%20checkOutDateLocalized%20listing%20guest%20money.hostPayout%20money.totalPaid%20money.totalRefunded%20money.balanceDue%20money.payments&filters=%5B%7B%22operator%22:%20%22$ne%22,%20%22field%22:%20%22balanceDue%22,%20%22value%22:%200%7D,%20%7B%22operator%22:%20%22$eq%22,%20%22field%22:%20%22status%22,%20%22value%22:%20%22confirmed%22%7D%5D&sort=_id&skip=0&limit=100", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8")) ``` -------------------------------- ### OpenAPI Definition for Get Languages Source: https://open-api-docs.guesty.com/reference/getlanguages This JSON defines the OpenAPI specification for the GET /marketing/languages endpoint, including request parameters, response schemas, and examples. ```json { "openapi": "3.0.3", "info": { "title": "GUESTY OPEN API", "description": "Guesty Open API documentation", "version": "1" }, "servers": [ { "url": "https://open-api.guesty.com/v1" } ], "security": [ { "bearerAuth": [] } ], "tags": [ { "name": "Marketing fields" } ], "paths": { "/marketing/languages": { "get": { "operationId": "getLanguages", "summary": "Retrieve a list of supported languages.", "description": "Retrieve a list of supported languages.", "tags": [ "Marketing fields" ], "parameters": [], "responses": { "200": { "description": "Return a list of supported languages", "content": { "application/json": { "schema": { "type": "array", "items": { "type": "object", "properties": { "name": { "type": "string" }, "slug": { "type": "string" } }, "example": { "name": "German - Germany", "slug": "de_de" } }, "example": [ { "name": "German - Germany", "slug": "de_de" }, { "name": "Italian - Italy", "slug": "it_it" }, { "name": "Portuguese - Portugal", "slug": "pt_pt" }, { "name": "Polish - Poland", "slug": "pl_pl" }, { "name": "Spanish - Spain", "slug": "es_es" }, { "name": "English - United States", "slug": "en_us" }, { "name": "Japanese - Japan", "slug": "ja_jp" }, { "name": "Greek - Greece", "slug": "el_gr" }, { "name": "Korean - Korea", "slug": "ko_kr" }, { "name": "Romanian - Romania", "slug": "ro_ro" }, { "name": "Indonesian - Indonesia", "slug": "in_in" }, { "name": "French - France", "slug": "fr_fr" }, { "name": "Chinese - China", "slug": "zh_chs" }, { "name": "Dutch - Netherlands", "slug": "nl_nl" } ] } } } }, "403": { "description": "Unauthorized Request.", "content": { "application/json": { "schema": { "type": "object", "properties": { "error": { "type": "object", "properties": { "code": { "type": "string", "example": "UNAUTHORIZED" }, "message": { "type": "string", "example": "Unauthorized" } } } } } } } } } } } }, "components": { "securitySchemes": { "bearerAuth": { "type": "apiKey", "name": "authorization", "in": "header" } } }, "x-kong-upstream-prefix": "/quotes", "x-kong-route-transformations": [ { "configuration": "v1", "routeExtpath": "/quotes", "stripPrefix": "/v1/quotes" } ] } ``` -------------------------------- ### Example Sources Configuration Source: https://open-api-docs.guesty.com/reference/post_additional-fees-account Defines a configuration for a 'BABY_BED' fee, specifying sources, value, multiplier, bundling, and override conditions. ```json { "sources": [ "travel agent Gabriel", "source2" ], "type": "BABY_BED", "value": 10, "isPercentage": false, "multiplier": "PER_STAY", "isBundled": true, "isOverrideConditions": false, "conditions": [] } ``` -------------------------------- ### Making a GET Request with Access Token Source: https://open-api-docs.guesty.com/docs/authentication Include your access token in the 'Authorization' header as a 'Bearer' token when making API requests. This example shows a GET request to retrieve listings. ```curl curl --location --request GET 'https://open-api.guesty.com/v1/listings' \ --header 'accept: application/json' \ --header 'Authorization: Bearer eyJraWQiOiJydFFaWXhoTzBtNlllbWZaRnRBRXJORFVkWThZOFlPeGxndVZabmpJZVNvIiwiYWxnIjoiUlMyNTYifQ.eyJ2ZXIiOjEsImp0aSI6IkFULlVWdkZ5NW5ES1h4SlBvUVUzbWN3ZS1ORXp0eHo0NWNQVktZVUFxM3V5RXMiLCJpc3MiOiJodHRwczovL2xvZ2luLmd1ZXN0eS5jb20vb2F1dGgyL2F1czFwOHFyaDUzQ2NRVEk5NWQ3IiwiYXVkIjoiaHR0cHM6Ly9vcGVuLWFwaS5ndWVzdHkuY29tIiwiaWF0IjoxNjU5NTM3NjUwLCJleHAiOjE2NTk2MjQwNTAsImNpZCI6IjBvYTViaWw0MzB4OHpMeldCNWQ3Iiwic2NwIjpbIm9wZW4tYXBpIl0sInJlcXVlc3RlciI6IkVYVEVSTkFMIiwiYWNjb3VudElkIjoiNjJhMDZkMmYyMjUxMzAwMDM1OWVlODkzIiwic3ViIjoiMG9hNWJpbDQzMHg4ekx6V0I1ZDciLCJ1c2VyUm9sZXMiOlt7InJvbGVJZCI6eyJwZXJtaXNzaW9ucyI6WyJhZG1pbiJdfX1dLCJyb2xlIjoidXNlciIsImlhbSI6InYzIiwibmFtZSI6IkNTIHwgVEEtMSB8IE1vc2hlIn0.LlZZUhM4WTsIsgmuqLasl-5WtNx0N8MvpmSGerSz5DpvO2AkcOhZAuYgPh1xqocGpwcKLMBokYvSyC0xRtptDEpaEY8X__ozvDS_UpUp2vKdtU2t-1ns7ut5qZlGhf6ffZAR0K1WXEb1081n-0Ms5qxfy1HbWkmyPUt0tgN-xAmRgnbSX01YELZ-_vovpitsxC0JYPPpBOi_w8kxlxsqKLWiFzDe5SpzBUYncjJEafISXzo5PNHEweHkvguXXM9xVXlNpE_q0DfQvQ41mn8TDnhUVtspscG3WmKV86k5QAjqHyYMJ2_2WOWRWrjfeyKc5ePC1HqCANRxOO7oS7dQcA' ``` -------------------------------- ### Example Fee Configuration Source: https://open-api-docs.guesty.com/reference/post_additional-fees-account Illustrates a configuration for an 'INTERNET' fee, including its value, percentage applicability, target fee type, and bundling status. ```json { "type": "INTERNET", "value": 15, "isPercentage": true, "targetFee": "PAYOUT", "isBundled": true } ``` -------------------------------- ### Create Guest using Python http.client Source: https://open-api-docs.guesty.com/docs/create-guest-and-payment-method This Python example shows how to create a guest using the http.client library. It establishes an HTTPS connection, prepares the JSON payload, and sends a POST request. ```python import http.client import json conn = http.client.HTTPSConnection("open-api.guesty.com") payload = json.dumps({ "firstName": "Irving", "lastName": "Washington", "hometown": "New York", "email": "ichabod@hotmail.com", "phone": "+12128765234", "nationality": "us", "pronouns": "he/him/his", "gender": "male", "preferredLanguage": "en" }) headers = { 'accept': 'application/json', 'content-type': 'application/json' } conn.request("POST", "/v1/guests-crud", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8")) ``` -------------------------------- ### Create a Listing Example Source: https://open-api-docs.guesty.com/docs/postman-guide Use this snippet to create a new listing in your Guesty account. Ensure the 'Body' tab is correctly configured with listing details. A successful request returns an HTTP 201 OK status. ```Postman POST /listings Body: { "listing_name": "My Awesome Listing", "address": { "street": "123 Main St", "city": "Anytown", "state": "CA", "zip_code": "90210", "country": "USA" }, "description": "A beautiful place to stay.", "price": { "amount": 100, "currency": "USD" } } ``` -------------------------------- ### OpenAPI Definition for Get Channels Source: https://open-api-docs.guesty.com/reference/getchannels This JSON defines the OpenAPI specification for the `getChannels` endpoint, including request parameters, response schemas, and examples. ```json { "openapi": "3.0.3", "info": { "title": "GUESTY OPEN API", "description": "Guesty Open API documentation", "version": "1" }, "servers": [ { "url": "https://open-api.guesty.com/v1" } ], "security": [ { "bearerAuth": [] } ], "tags": [ { "name": "Marketing fields" } ], "paths": { "/marketing/channels": { "get": { "operationId": "getChannels", "summary": "Retrieve a list of supported channels.", "description": "Retrieve a list of supported channels.", "tags": [ "Marketing fields" ], "parameters": [], "responses": { "200": { "description": "Return a list of supported channels", "content": { "application/json": { "schema": { "type": "array", "items": { "type": "object", "properties": { "name": { "type": "string" }, "slug": { "type": "string" } }, "example": { "name": "Airbnb", "slug": "airbnb" } }, "example": [ { "name": "Airbnb", "slug": "airbnb" } ] } } } }, "403": { "description": "Unauthorized Request.", "content": { "application/json": { "schema": { "type": "object", "properties": { "error": { "type": "object", "properties": { "code": { "type": "string", "example": "UNAUTHORIZED" }, "message": { "type": "string", "example": "Unauthorized" } } } } } } } } } } } }, "components": { "securitySchemes": { "bearerAuth": { "type": "apiKey", "name": "authorization", "in": "header" } } }, "x-kong-upstream-prefix": "/quotes", "x-kong-route-transformations": [ { "configuration": "v1", "routeExtpath": "/quotes", "stripPrefix": "/v1/quotes" } ] } ``` -------------------------------- ### Create Guest Payment Method (Python) Source: https://open-api-docs.guesty.com/docs/create-guest-and-payment-method This Python example shows how to create a guest payment method using the http.client library. The payload and headers must be correctly formatted. ```python import http.client import json conn = http.client.HTTPSConnection("open-api.guesty.com") payload = json.dumps({ "_id": "6265d1b6a08a2710e00057b82", "paymentProviderId": "5fe4b21675087f01a3c5ab5b", "reservationId": "563e0b6a08a2710e00057b82" }) headers = { 'content-type': 'application/json', 'Authorization': 'Bearer ' } conn.request("POST", "/v1/guests/64c7afe8a1237cba15116c95/payment-methods", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8")) ``` -------------------------------- ### OpenAPI Definition for List Cities Source: https://open-api-docs.guesty.com/reference/get_listings-cities This OpenAPI definition describes the GET /listings/cities endpoint, which returns an array of city names. It includes the response schema and an example. ```json { "openapi": "3.0.3", "info": { "title": "GUESTY OPEN API", "description": "Guesty Open API documentation", "version": "1" }, "servers": [ { "url": "https://open-api.guesty.com/v1" } ], "security": [ { "bearerAuth": [] } ], "tags": [ { "name": "Listings" } ], "paths": { "/listings/cities": { "get": { "tags": [ "Listings" ], "summary": "List all cities", "responses": { "200": { "description": "Array of cities (strings).", "content": { "application/json": { "example": [ "Burnt Ranch", "New York", "Autun", "Kfar Sirkin", "London", "Newton", "Atlanta", "Montpelier", "Tel Aviv-Yafo", "Decatur", "Vancouver", "Amsterdam", "Cuyahoga Falls", "Palo Alto", "Ramat Gan" ] } } } }, "security": [ { "bearerAuth": [] } ] } } }, "components": { "securitySchemes": { "bearerAuth": { "type": "apiKey", "name": "authorization", "in": "header" } } }, "x-kong-upstream-prefix": "/quotes", "x-kong-route-transformations": [ { "configuration": "v1", "routeExtpath": "/quotes", "stripPrefix": "/v1/quotes" } ] } ``` -------------------------------- ### cURL Request Example Source: https://open-api-docs.guesty.com/reference-link/transactionscontroller_createexpensebylisting Demonstrates how to make a POST request to create an expense by listing using cURL. Includes setting the URL, accept, and content-type headers. ```shell curl --request POST \ --url https://open-api.guesty.com/v1/business-models-api/transactions/expenses-by-listing \ --header 'accept: application/json' \ --header 'content-type: application/json' ``` -------------------------------- ### Querying Specific Reservation Fields Source: https://open-api-docs.guesty.com/docs/how-to-search-for-reservations To retrieve only the fields you need, append the `fields` parameter to your GET request. This example shows how to include localized check-in and check-out dates. ```http GET https://open-api.guesty.com/v1/reservations?fields=checkInDateLocalized checkOutDateLocalized ``` -------------------------------- ### HTTP Request to Fetch Listings Source: https://open-api-docs.guesty.com/docs/quick-start-guide This is an example HTTP GET request to fetch a list of listings from the Guesty API. It includes the required 'Authorization' header with the 'Bearer' token. ```http GET https://open-api.guesty.com/v1/listings Authorization: Bearer YOUR_ACCESS_TOKEN ``` -------------------------------- ### Token Storage Example Source: https://open-api-docs.guesty.com/docs Demonstrates how to cache an access token to avoid frequent re-authentication. This example includes implementations in JavaScript, Python, and PHP. ```JavaScript let tokenCache = { token: null, expiresAt: null }; async function getToken() { const now = Date.now(); if (tokenCache.token && tokenCache.expiresAt > now) { return tokenCache.token; } const response = await fetch('https://open-api.guesty.com/oauth2/token', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ clientId: 'YOUR_CLIENT_ID', clientSecret: 'YOUR_CLIENT_SECRET' }) }); const data = await response.json(); tokenCache.token = data.access_token; tokenCache.expiresAt = now + 24 * 60 * 60 * 1000; // 24 hours return tokenCache.token; } ``` ```Python import time import requests token_cache = { 'token': None, 'expires_at': 0 } def get_token(): now = time.time() if token_cache['token'] and token_cache['expires_at'] > now: return token_cache['token'] response = requests.post('https://open-api.guesty.com/oauth2/token', json={ 'clientId': 'YOUR_CLIENT_ID', 'clientSecret': 'YOUR_CLIENT_SECRET' }) data = response.json() token_cache['token'] = data['access_token'] token_cache['expires_at'] = now + 86400 # 24 hours in seconds return token_cache['token'] ``` ```PHP class TokenCache { private static $token = null; private static $expiresAt = 0; public static function getToken() { if (self::$token && self::$expiresAt > time()) { return self::$token; } $payload = json_encode([ 'clientId' => 'YOUR_CLIENT_ID', 'clientSecret' => 'YOUR_CLIENT_SECRET' ]); $ch = curl_init('https://open-api.guesty.com/oauth2/token'); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:application/json']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $data = json_decode($response, true); self::$token = $data['access_token']; self::$expiresAt = time() + 86400; // 24 hours return self::$token; } } ``` -------------------------------- ### OpenAPI Definition for Get Complex by ID Source: https://open-api-docs.guesty.com/reference/complexescontroller_getcomplexbyid This OpenAPI definition outlines the GET request for retrieving a specific complex by its ID. It specifies the path parameter, expected response structures for success (200 OK), unauthorized access (403 Forbidden), and not found (404 Not Found) errors, including example payloads. ```json { "openapi": "3.0.3", "info": { "title": "GUESTY OPEN API", "description": "Guesty Open API documentation", "version": "1" }, "servers": [ { "url": "https://open-api.guesty.com/v1" } ], "security": [ { "bearerAuth": [] } ], "tags": [ { "name": "Complexes" } ], "paths": { "/properties-api/complexes/{id}": { "get": { "operationId": "ComplexesController_getComplexById", "summary": "Get complex", "description": "Get a specific complex based on the complexId", "tags": [ "Complexes" ], "parameters": [ { "name": "id", "required": true, "in": "path", "description": "The id of the complex to retrieve", "schema": { "type": "string" } } ], "responses": { "200": { "description": "Return the requested complex.", "content": { "application/json": { "schema": { "type": "object", "properties": { "id": { "type": "string" }, "title": { "type": "string" }, "nickname": { "type": "string" }, "propertyIds": { "type": "array", "items": { "type": "string" } }, "tags": { "type": "array", "items": { "type": "string" } } }, "example": { "id": "645774fe76e5da340bf915e7", "title": "Complex 1", "nickname": "C1", "propertyIds": [ "6457751476e5da340bf915e8", "6457751e76e5da340bf915e9" ], "tags": [ "tag1", "tag2" ] } } } } }, "403": { "description": "Unauthorized Request", "content": { "application/json": { "schema": { "type": "object", "properties": { "error": { "type": "object", "properties": { "code": { "type": "string", "example": "UNAUTHORIZED" }, "message": { "type": "string", "example": "Unauthorized" } } } } } } } }, "404": { "description": "Complex not found", "content": { "application/json": { "schema": { "type": "object", "properties": { "error": { "type": "object", "properties": { "message": { "type": "string", "example": "Not Found" }, "status": { "type": "integer", "example": 404 }, "data": { "type": "string", "example": "Could not find complex" } } } } } } } } } } } }, "components": { "securitySchemes": { "bearerAuth": { "type": "apiKey", "name": "authorization", "in": "header" } } }, "x-kong-upstream-prefix": "/quotes", "x-kong-route-transformations": [ { "configuration": "v1", "routeExtpath": "/quotes", "stripPrefix": "/v1/quotes" } ] } ``` -------------------------------- ### cURL Request Example Source: https://open-api-docs.guesty.com/reference-link/externalintegrationscontroller_getbrandbyproperty Demonstrates how to make a GET request to retrieve brand information by property ID using cURL. Ensure you replace 'propertyId' with the actual property ID. ```Shell curl --request GET \ --url https://open-api.guesty.com/v1/account-brands/properties/propertyId \ --header 'accept: application/json' ``` -------------------------------- ### Post Immediate Payment (Python) Source: https://open-api-docs.guesty.com/docs/posting-a-guest-payment This Python example shows how to make an immediate payment request using the http.client library. It constructs the JSON payload and sends a POST request to the API. ```python import http.client import json conn = http.client.HTTPSConnection("open-api.guesty.com") payload = json.dumps({ "paymentMethod": { "method": "AMARYLLIS", "saveForFutureUse": True, "id": "64da2367d8d9771c02befbb2" }, "amount": 500, "note": "Deposit" }) headers = { 'accept': 'application/json', 'content-type': 'application/json' } conn.request("POST", "/v1/reservations/64da254383ad1500284bd0c0/payments", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8")) ``` -------------------------------- ### Request Token Example Source: https://open-api-docs.guesty.com/docs Examples of how to request an access token using different programming languages and tools. Includes Node.js, Python, cURL, and PHP. ```Node.js const axios = require('axios'); async function getToken() { const response = await axios.post('https://open-api.guesty.com/oauth2/token', { clientId: 'YOUR_CLIENT_ID', clientSecret: 'YOUR_CLIENT_SECRET' }); console.log(response.data.access_token); } getToken(); ``` ```Python import requests response = requests.post( 'https://open-api.guesty.com/oauth2/token', json={ 'clientId': 'YOUR_CLIENT_ID', 'clientSecret': 'YOUR_CLIENT_SECRET' } ) print(response.json()['access_token']) ``` ```cURL curl -X POST https://open-api.guesty.com/oauth2/token \ -H "Content-Type: application/json" \ -d '{"clientId":"YOUR_CLIENT_ID","clientSecret":"YOUR_CLIENT_SECRET"}' ``` ```PHP 'YOUR_CLIENT_ID', 'clientSecret' => 'YOUR_CLIENT_SECRET' ]); $ch = curl_init('https://open-api.guesty.com/oauth2/token'); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:application/json']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $data = json_decode($response, true); echo $data['access_token']; ?> ``` -------------------------------- ### Search Reservations with cURL (PHP) Source: https://open-api-docs.guesty.com/docs/how-to-search-for-reservations This PHP example uses cURL to perform a GET request for reservations. It configures various cURL options, including the URL, headers, and timeout. ```php 'https://open-api.guesty.com/v1/reservations?fields=_id%20confirmationCode%20status%20checkInDateLocalized%20checkOutDateLocalized%20listing%20guest%20money.hostPayout%20money.totalPaid%20money.totalRefunded%20money.balanceDue%20money.payments&filters=[{%22operator%22%3A%20%22%24ne%22%2C%20%22field%22%3A%20%22balanceDue%22%2C%20%22value%22%3A%200}%2C%20{%22operator%22%3A%20%22%24eq%22%2C%20%22field%22%3A%20%22status%22%2C%20%22value%22%3A%20%22confirmed%22}]&sort=_id&skip=0&limit=100', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => false, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'Authorization: Bearer {token}' ), )); $response = curl_exec($curl); curl_close($curl); echo $response; ?> ``` -------------------------------- ### cURL Request Example Source: https://open-api-docs.guesty.com/reference-link/uploadbyurls This example demonstrates how to make a POST request to the Guesty API to upload new property photos using URLs. Ensure the provided URLs are accessible to Guesty. ```shell curl --request POST \ --url https://open-api.guesty.com/v1/properties-api/property-photos/property-photos/propertyId \ --header 'accept: application/json' \ --header 'content-type: application/json' ``` -------------------------------- ### Search Reservations with Fetch API (JavaScript) Source: https://open-api-docs.guesty.com/docs/how-to-search-for-reservations Use the Fetch API to make a GET request to search for reservations. This example filters for reservations that are not fully paid and have a 'confirmed' status. ```javascript myHeaders.append("Authorization", "Bearer {token}"); const requestOptions = { method: "GET", headers: myHeaders, redirect: "manual" }; fetch("https://open-api.guesty.com/v1/reservations?fields=_id confirmationCode status checkInDateLocalized checkOutDateLocalized listing guest money.hostPayout money.totalPaid money.totalRefunded money.balanceDue money.payments&filters=[{\"operator\": \"$ne\", \"field\": \"balanceDue\", \"value\": 0}, {\"operator\": \"$eq\", \"field\": \"status\", \"value\": \"confirmed\"}]&sort=_id&skip=0&limit=100", requestOptions) .then((response) => response.text()) .then((result) => console.log(result)) .catch((error) => console.error(error)); ``` ``` -------------------------------- ### Get All Journal Entries Source: https://open-api-docs.guesty.com/reference/journalentriescontroller_getall Retrieves a paginated list of journal entries. You can control the number of entries returned and the starting point of the results using the 'skip' and 'limit' query parameters. ```APIDOC ## GET /journal-entries ### Description Retrieves a list of all journal entries, supporting pagination. ### Method GET ### Endpoint /journal-entries #### Query Parameters - **skip** (integer) - Optional - The number of entries to skip from the beginning of the list. - **limit** (integer) - Optional - The maximum number of entries to return. ### Response #### Success Response (200) - **skip** (integer) - The number of entries skipped. - **limit** (integer) - The maximum number of entries returned. - **current** (integer) - The number of entries in the current response. - **total** (integer) - The total number of available journal entries. - **data** (array) - An array of journal entry objects. - **id** (string) - Unique identifier for the journal entry. - **transactionId** (string) - Identifier for the associated transaction. - **date** (string) - The date of the journal entry (ISO 8601 format). - **description** (string) - A description of the journal entry. - **ledger** (string) - The ledger associated with the entry. - **guest** (object) - Information about the guest. - **id** (string) - Guest ID. - **name** (string) - Guest name. - **vendor** (object) - Information about the vendor. - **id** (string) - Vendor ID. - **name** (string) - Vendor name. - **owner** (object) - Information about the owner. - **id** (string) - Owner ID. - **name** (string) - Owner name. - **amount** (number) - The amount of the journal entry. - **name** (string) - The name of the journal entry. - **listing** (object) - Information about the listing. - **id** (string) - Listing ID. - **name** (string) - Listing name. - **chargeType** (string) - The type of charge. - **reservationConfirmationCode** (string) - The confirmation code for the reservation. - **paymentConfirmationCode** (string) - The confirmation code for the payment. - **chargeCode** (string) - The code for the charge. - **trigger** (string) - The trigger for the journal entry. - **attachments** (array) - A list of attachments. - **urlThumbnail** (string) - URL of the thumbnail. - **uploadedBy** (string) - User who uploaded the attachment. - **uploadedAt** (string) - Timestamp of upload. - **originalFilename** (string) - Original filename. - **originalExtension** (string) - Original file extension. - **recognized** (boolean) - Indicates if the entry has been recognized. #### Response Example (200) { "skip": 0, "limit": 10, "current": 5, "total": 100, "data": [ { "id": "entry_123", "transactionId": "txn_abc", "date": "2023-10-27T10:00:00Z", "description": "Room charge", "ledger": "expenses", "guest": { "id": "guest_456", "name": "John Doe" }, "vendor": { "id": "vendor_789", "name": "Hotel Services" }, "owner": { "id": "owner_101", "name": "Property Owner" }, "amount": 150.75, "name": "Standard Room", "listing": { "id": "listing_202", "name": "Cozy Apartment" }, "chargeType": "NIGHTLY", "reservationConfirmationCode": "CONF789XYZ", "paymentConfirmationCode": "PAY123ABC", "chargeCode": "RCHG001", "trigger": "RESERVATION_CREATED", "attachments": [ { "urlThumbnail": "https://example.com/thumbnails/img1.jpg", "uploadedBy": "user_a", "uploadedAt": "2023-10-27T10:05:00Z", "originalFilename": "receipt.pdf", "originalExtension": "pdf" } ], "recognized": true } ] } #### Error Response (400) - **error** (object) - **message** (string) - Error message. - **code** (string) - Error code (e.g., "VALIDATION_FAILED"). - **status** (number) - HTTP status code (400). - **data** (array) - Array of validation error details. #### Response Example (400) { "error": { "message": "Bad Request", "code": "VALIDATION_FAILED", "status": 400, "data": [ "title must be longer than or equal to 3 characters", "entries.0.amount should not be empty" ] } } #### Error Response (403) - **error** (object) - **message** (string) - Error message (e.g., "Missing account_id error message"). - **status** (number) - HTTP status code (403). #### Response Example (403) { "error": { "message": "Missing account_id error message", "status": 403 } } #### Error Response (500) - **error** (object) - **message** (string) - Error message (e.g., "Something went wrong"). - **status** (number) - HTTP status code (500). #### Response Example (500) { "error": { "message": "Something went wrong", "status": 500 } } ``` -------------------------------- ### Get Fields Per Channel Source: https://open-api-docs.guesty.com/reference/getfieldsperchannel Retrieves a comprehensive list of fields available for a given channel, including their types, descriptions, and examples. Supports multiple language translations for field content. ```APIDOC ## GET /channels/{channelId}/fields ### Description Retrieves detailed information about fields associated with a specific channel. This includes field properties, their types, and optional translation data for different locales. ### Method GET ### Endpoint /channels/{channelId}/fields ### Parameters #### Path Parameters - **channelId** (string) - Required - The unique identifier of the channel. ### Response #### Success Response (200) - **active** (boolean) - Indicates if translation is active for the field. - **title** (string) - The title of the field. - **summary** (string) - A brief summary of the field. - **space** (string) - Information about the space related to the field. - **access** (string) - Details about access permissions. - **neighborhood** (string) - Information about the neighborhood. - **transit** (string) - Details about nearby transit options. - **notes** (string) - Additional notes about the field, with an example. - **interactionWithGuests** (string) - Information on guest interactions. - **checkInInstructions** (object) - Instructions for check-in, containing: - **primaryCheckIn** (string) - Primary check-in method. - **alternativeCheckIn** (string) - Alternative check-in method. - **notes** (string) - Notes related to check-in. - **welcomeMessage** (string) - A welcome message for guests. - **de_de** (object) - Translation object for German (de-de) locale, containing similar properties as the main object for localized content. #### Response Example { "active": true, "title": "Example Title", "summary": "Example Summary", "space": "Entire home", "access": "Guest access", "neighborhood": "Quiet neighborhood", "transit": "Easy access to public transport", "notes": "Some notes about listing", "interactionWithGuests": "Guests can interact via app", "checkInInstructions": { "primaryCheckIn": "Self check-in with keypad", "alternativeCheckIn": "Contact host for alternative", "notes": "Please respect quiet hours", "welcomeMessage": "Welcome!" }, "de_de": { "active": true, "title": "Beispiel Titel", "summary": "Beispiel Zusammenfassung", "space": "Ganze Unterkunft", "access": "Gästezugang", "neighborhood": "Ruhige Nachbarschaft", "transit": "Gute Anbindung an öffentliche Verkehrsmittel", "notes": "Einige Hinweise zur Unterkunft", "interactionWithGuests": "Gäste können per App interagieren", "checkInInstructions": { "primaryCheckIn": "Selbst-Check-in mit Tastatur", "alternativeCheckIn": "Kontaktieren Sie den Gastgeber für Alternativen", "notes": "Bitte Nachtruhe beachten", "welcomeMessage": "Willkommen!" } } } ```