Files
notes/projects/sbx/it-glue/api_with_python.md
Petar Cubela 221ac5f923 20251013
2025-10-13 00:07:28 +02:00

44 lines
1.3 KiB
Markdown

## Sources
- [it-glue api](https://api.itglue.com/developer/)
- [it-glue api - getting started](https://help.itglue.kaseya.com/help/Content/1-admin/it-glue-api/getting-started-with-the-it-glue-api.html)
## base python template
```python3
import requests
import json
import os
from dotenv import load_dotenv
# Load the .env file so the API Token can be read by the script
load_dotenv()
# Set the 'token' variable to the value of 'api_token' from the .env file
# Rename file .env.example to .env and add your own API token
# Remember to add .env to your .gitignore file to avoid uploading the token to your Git repo
token = os.getenv('api_token')
# Set variables to match your own IT Glue installation
itglue_protocol = 'https'
itglue_host = 'api.eu.itglue.com'
itglue_port = '443'
# Build the URL for the API request
url = itglue_protocol+'://'+itglue_host+':'+itglue_port+"/organizations?sort=id"
# Set the payload and headers for the API request
payload = ""
headers = {
'Content-Type': 'application/vnd.api+json',
#'Authorization': 'Token '+ token
'x-api-key': 'api_token'
}
# Send the API request and display the result in pretty json format
response = requests.request("GET", url, headers=headers, data=payload)
pretty_json = json.loads(response.text)
print (json.dumps(pretty_json, indent=4))
```