Created
December 22, 2025 17:15
-
-
Save PeterTough2/1145a15389e11dc60868ec28a50067a2 to your computer and use it in GitHub Desktop.
Igloo API Authentication and Retrieve Door Lock Codes - Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //adapted for Zapier | |
| import requests | |
| import time | |
| # ----------------------------- | |
| # INPUTS FROM ZAPIER | |
| # ----------------------------- | |
| stored_token = input_data.get("stored_token") # From Storage by Zapier | |
| stored_expires_at = input_data.get("stored_expires_at") # Unix timestamp (string) | |
| DEVICE_ID = "xxxxxxxxxxxx" | |
| # ----------------------------- | |
| # CONFIG | |
| # ----------------------------- | |
| AUTH_URL = "https://auth.igloohome.co/oauth2/token" | |
| PIN_URL = f"https://api.igloodeveloper.co/igloohome/devices/{DEVICE_ID}/algopin/hourly" | |
| AUTH_HEADER = "Basic xxxxxxxxxxx==" | |
| SCOPES = ( | |
| "igloohomeapi/algopin-permanent " | |
| "igloohomeapi/algopin-onetime " | |
| "igloohomeapi/algopin-hourly " | |
| "igloohomeapi/algopin-daily " | |
| "igloohomeapi/get-devices " | |
| "igloohomeapi/lock-bridge-proxied-job " | |
| "igloohomeapi/unlock-bridge-proxied-job" | |
| ) | |
| NOW = int(time.time()) | |
| # ----------------------------- | |
| # STEP 1: GET OR REFRESH TOKEN | |
| # ----------------------------- | |
| def get_access_token(): | |
| # Use cached token if still valid | |
| if stored_token and stored_expires_at: | |
| try: | |
| if int(stored_expires_at) > NOW: | |
| return { | |
| "access_token": stored_token, | |
| "expires_at": int(stored_expires_at), | |
| "from_cache": True | |
| } | |
| except: | |
| pass | |
| # Otherwise login again | |
| response = requests.post( | |
| AUTH_URL, | |
| headers={ | |
| "Authorization": AUTH_HEADER, | |
| "Content-Type": "application/x-www-form-urlencoded" | |
| }, | |
| data={ | |
| "grant_type": "client_credentials", | |
| "scope": SCOPES | |
| }, | |
| verify=False, | |
| timeout=30 | |
| ) | |
| response.raise_for_status() | |
| data = response.json() | |
| expires_at = NOW + int(data.get("expires_in", 86400)) - 60 # buffer | |
| return { | |
| "access_token": data["access_token"], | |
| "expires_at": expires_at, | |
| "from_cache": False | |
| } | |
| # ----------------------------- | |
| # STEP 2: GENERATE PIN | |
| # ----------------------------- | |
| def generate_pin(access_token): | |
| response = requests.post( | |
| PIN_URL, | |
| headers={ | |
| "Authorization": f"Bearer {access_token}", | |
| "Content-Type": "application/json", | |
| "Accept": "application/json" | |
| }, | |
| json={ | |
| "variance": 1, | |
| # "startDate": input_data.get("startDate"), | |
| "startDate": "2025-12-25T12:00:00+01:00", | |
| "endDate": "2025-12-25T16:00:00+01:00", | |
| # "endDate": input_data.get("endDate"), | |
| "accessName": "Testing zaps Maintenance guy test" | |
| }, | |
| verify=False, | |
| timeout=30 | |
| ) | |
| response.raise_for_status() | |
| return response.json() | |
| # ----------------------------- | |
| # MAIN FLOW | |
| # ----------------------------- | |
| token_info = get_access_token() | |
| pin_data = generate_pin(token_info["access_token"]) | |
| # ----------------------------- | |
| # RETURN STRUCTURED DATA | |
| # ----------------------------- | |
| return { | |
| # Token info (store these back into Storage by Zapier) | |
| "access_token": token_info["access_token"], | |
| "token_expires_at": token_info["expires_at"], | |
| "token_from_cache": token_info["from_cache"], | |
| # PIN info (for Gmail) | |
| "pin": pin_data.get("pin"), | |
| "pin_id": pin_data.get("pinId"), | |
| # Status | |
| "success": True | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment