The hoteliga API

Python Examples

The following examples are implemented using Python 2.7. You will need Requests library.

Token Request

Place the proper values to username, password, domain variables.

import requests
def token_request():
    username = "USERNAME"
    password = "PASSWORD"
    domain = "HOTELIGA_DOMAIN"
    token_url = "https://api.hoteliga.com/v1/Token"
    token_data = "grant_type=password&username="+username+"&password="+password+"&domain="+domain
    headers = {
		"Content-Type": "multipart/form-data",
        "Accept": "application/json"
	   }
    response = requests.post(token_url, data=token_data, headers=headers)
    json_response = response.json()
    print json_response
if __name__ == "__main__":
    token_request()
    

Get customer's data

Place the proper values to token and customer_id variables.

import requests
def get_customer():
    token = "TOKEN"
    customer_id = "ID"
    get_customer_url = "https://api.hoteliga.com/v1/Customer/"+customer_id
    headers = {
        "Authorization": "Bearer "+token,
        "Content-Type": "application/json",
        "Accept": "application/json"
    }
    response = requests.get(get_customer_url, headers=headers)
    json_response = response.json()
    print json_response
if __name__ == "__main__":
    get_customer()
        
import requests
from xml.etree import ElementTree
def get_customer():
    token = "TOKEN"
    customer_id = "ID"
    get_customer_url = "https://api.hoteliga.com/v1/Customer/"+customer_id
    headers = {
        "Authorization": "Bearer "+token,
        "Content-Type": "application/json",
        "Accept": "application/xml"
    }
    response = requests.get(get_customer_url, headers=headers)
    tree = ElementTree.fromstring(response.content)
    for elem in tree._children:
        if elem.text != None: print elem.tag+": "+elem.text
if __name__ == "__main__":
    get_customer()
    

Add Customer

Place the proper values to token, create_customer_data_json and create_customer_data_xml variables.

import requests
import json
def create_customer():
    token = "TOKEN"
    create_customer_data_json = {"lastName": "Smith",
                                 "firstName": "John",
                                 "email": "johnsmith@example.com"}
    create_customer_url = "https://api.hoteliga.com/v1/Customer"
    headers = {
        "Authorization": "Bearer " + token,
        "Content-Type": "application/json",
        "Accept": "application/json"
    }
    response = requests.post(create_customer_url, 
                data=json.dumps(create_customer_data_json), headers=headers)
    json_response = response.json()
    print json_response
if __name__ == "__main__":
    create_customer()
        
import requests
import json
def create_customer():
    token = "TOKEN"
    create_customer_data_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" \
                    "<Customer><LastName>Smith</LastName>" \
                    "<FirstName>John</FirstName>" \
                    "<Email>johnsmith@example.com</Email>" \
                    "</Customer>"
    create_customer_url = "https://api.hoteliga.com/v1/Customer"
    headers = {
        "Authorization": "Bearer " + token,
        "Content-Type": "application/xml",
        "Accept": "application/json"
    }
    response = requests.post(create_customer_url, 
            data=create_customer_data_xml, headers=headers)
    json_response = response.json()
    print json_response
if __name__ == "__main__":
    create_customer()