20251013
This commit is contained in:
44
projects/sbx/it-glue/api_with_python.md
Normal file
44
projects/sbx/it-glue/api_with_python.md
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
|
||||
## 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))
|
||||
```
|
||||
Reference in New Issue
Block a user