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

Query the root API path
curl -s \
    -H "Authorization: Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
    https://deploy.c1engineering.com/api/
List the projects you can access
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

Format with jq
curl -s \
    -H "Authorization: Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
    https://deploy.c1engineering.com/api/projects/projects/ | jq

Powershell has a curl-like utility for making API requests too

Query the root API path
Invoke-RestMethod `
    -Headers @{Authorization="Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"} `
    -Uri https://deploy.c1engineering.com/api/
List the projects you can access
Invoke-RestMethod `
    -Headers @{Authorization="Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"} `
    -Uri https://deploy.c1engineering.com/api/projects/projects/

Use ConvertTo-Json to output the raw JSON response

Output raw JSON
Invoke-RestMethod `
    -Headers @{Authorization="Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"} `
    -Uri https://deploy.c1engineering.com/api/projects/projects/ | ConvertTo-Json

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.

Query the root API path
import requests

response = requests.get(
    'https://deploy.c1engineering.com/api/',
    headers={
        'Authorization':
        'Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    },
)

print(response.json())
List the projects you can access
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

Format with json the library
import json
import requests

response = requests.get(
    'https://deploy.c1engineering.com/api/projects/projects/',
    headers={
        'Authorization':
        'Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    },
)

print(json.dumps(response.json(), indent=4))