API Beginner Guide
Converting curl to Python
The examples on the API Reference page use curl (Client URL) while Python uses Python requests. There are a number of online tools to automatically convert from curl to python.
To get the curl command,
Look up the endpoint you want to use on the API reference page.
Select
Try it out.Enter the necessary parameters.
Select
Execute.Copy the resulting curl command.
In the most basic form, the curl command
curl my.curlcommand.com
becomes
import requests
response = requests.get('http://my.curlcommand.com')You will see the following options in the curl commands on the API Reference page.
-H means header.
-X means the string is passed "as is" without interpretation.
becomes
API Examples
Request a list of event codes
This is a straightforward request without parameters which can be used to to verify your connection.
The API call is
In this example, the API key is part of your API call, which means you must update all API calls when the key changes. A better practice is to put this API key in the headers so it is easier to maintain. The full code then becomes
Pretty-printing the result
The list of application codes was returned as a single line, which makes it difficult to read, so let's pretty-print the result.
Retrieving a list of projects
Now that we are able to retrieve information with the API, we can use it for a more practical request like retrieving a list of projects. This API request can also take parameters.
Retrieve all projects
First, we pass the request without parameters to retrieve all projects.
Single parameter
The easiest way to pass a parameter is by appending it to the API request. The following API request will list the projects with a filter on CAT as user tag.
Multiple parameters
If you only want entries that have both the tags CAT and WOLF, you would append them like this:
Copying Data
To copy data, you need to know:
Your generated API key.
The dataId of the files and folders which you want to copy (their syntax is fil.hexadecimal_identifier and fol.hexadecimal_identifier). You can select a file or folder in the GUI and select it to see the Id (Projects > your_project > Data > your_file > Data details > Id) or you can use the
/api/projects/{projectId}/dataendpoint.The destination project to which you want to copy the data.
The destination folder within the destination project to which you want to copy the data (fol.hexadecimal_identifier).
What to do when the destination files or folders already exist (OVERWRITE, SKIP or RENAME).
The full code will then be as follows:
Now that you can make individual API requests and work with responses, you can combine API calls into complete workflows. For an end-to-end example, see Run a Pipeline.
Last updated
Was this helpful?
