Accessing the API

As a developer, you will need to access the Digital Marketplace data API on a semi-regular basis. You will use it for making changes to frameworks, responding to second line support requests, and gathering information, amongst others.

Warning

The data API is powerful - you can use it to change just about anything that we store in the database. For this reason, when you access production, you should either:

You can access the API directly, or using the API client shell (recommended).

Use the API client shell

The API client shell is an IPython shell. This gives you benefits such as tab-completion and read-only mode.

To use it, check out the scripts repository. Then install requirements with invoke requirements-dev and enter the virtual environment (source venv/bin/activate).

If you have Digital Marketplace running locally, run ./scripts/api-clients-shell.py, alternatively you can access a remote environment by passing it as an argument e.g. ./scripts/api-clients-shell.py preview. You are now in an IPython shell. data is the data client and search is the search client. You can use tab completion to find the command you need.

To enter a read-only shell, use the --read-only option. This will only give you access to API methods that get or find information. Use this mode whenever possible to reduce the risk of accidentally making changes you did not intend.

Access the API directly

curl -H "Authorization: Bearer <API_TOKEN>" \
  -H "Content-Type: application/json" \
  -X <METHOD> \
  -d '<PAYLOAD>' \
  https://<API_ENDPOINT>/frameworks

Fill in the API token and endpoint for your environment and the method and payload for the API operation you wish to perform.