Test It Out
Now that you have an API key you can use to access Deploy, we can try out querying data.
Below are a few examples you can try for reading data from the API. In each example, you will need to substitute your API key where you see xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
You can use a simple CURL command to query the API
curl -s \
-H "Authorization: Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
https://deploy.c1engineering.com/api/
curl -s \
-H "Authorization: Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
https://deploy.c1engineering.com/api/projects/projects/
If you have the jq utility installed, you can use it to format the output
Powershell has a curl-like utility for making API requests too
Invoke-RestMethod `
-Headers @{Authorization="Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"} `
-Uri https://deploy.c1engineering.com/api/
Invoke-RestMethod `
-Headers @{Authorization="Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"} `
-Uri https://deploy.c1engineering.com/api/projects/projects/
Use ConvertTo-Json to output the raw JSON response
If we want to automate against the API, Python is a nice choice to start writing logic operations
Package Requirement
The below examples require the Python requests package to be installed.
Depending on your operating system, you may need to use a Python virtual environment (venv) to install the package and use it.
import requests
response = requests.get(
'https://deploy.c1engineering.com/api/',
headers={
'Authorization':
'Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
},
)
print(response.json())
import requests
response = requests.get(
'https://deploy.c1engineering.com/api/projects/projects/',
headers={
'Authorization':
'Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
},
)
print(response.json())
You can use the built-in Python json library to format the output so its easy to read