Run a job through the API#
Login to the API#
First thing you need to do is to authenticate in the API and obtain an access token.
Run job using a previously uploaded dataset#
The endpoint to run a job for a given use case is as follows:
curl -X POST https://api.quantum.moodysanalytics.com//problem/problem-urn
-H 'Authorization: Bearer {access_token}'
-H 'Content-Type: application/json'
-d '{"data_file_identifier": "070737d79192e816db1581409256bdefa0a834fb"}'
response = requests.post(
url=https://api.quantum.moodysanalytics.com//problem/maxcut,
json={"data_file_identifier": "070737d79192e816db1581409256bdefa0a834fb"},
headers={"Authorization": "Bearer " + access_token})
In the request’s body, you have to include the dataset id, which is a file already uploaded to the platform and that contains the input data for this execution.
After a successfull job is launched, the API returns the Job Id to be used later to check its status and get the output.
{
"detail": "Authorized. Processing file",
"job": "W4P3Q4YTSDU1"
}
Run job using providing inline data#
If your input data for the execution is not to large (less than 4MB) you can provide this data directly in the request in JSON format.
In this example, we are providing input data for the Max Cut use case:
curl -X POST https://api.quantum.moodysanalytics.com//problem/maxcut
-H 'Authorization: Bearer {access_token}'
-H 'Content-Type: application/json'
-d '{ "num_nodes": 6,
"adj_matrix": [[0, 9, 5, 2, 4, 1],
[9, 0, 3, 8, 7, 6],
[5, 3, 0, 2, 8, 4],
[2, 8, 2, 0, 9, 3],
[4, 7, 8, 9, 0, 2],
[1, 6, 4, 3, 2, 0]] }'
response = requests.post(
url=https://api.quantum.moodysanalytics.com//problem/maxcut,
json={ "num_nodes": 6,
"adj_matrix": [[0, 9, 5, 2, 4, 1],
[9, 0, 3, 8, 7, 6],
[5, 3, 0, 2, 8, 4],
[2, 8, 2, 0, 9, 3],
[4, 7, 8, 9, 0, 2],
[1, 6, 4, 3, 2, 0]] },
headers={"Authorization": "Bearer " + access_token})
Tip
Visit the use case’s details page in the web dashboard to check the input data format.
After a successfull job is launched, the API returns the Job Id to be used later to check its status and get the output.
{
"detail": "Authorized. Processing file",
"job": "W4P3Q4YTSDU1"
}
Check job status#
The check the status of a job, use the following API GET request providing the Job Id obtained at job execution:
curl -X GET https://api.quantum.moodysanalytics.com//job/W4P3Q4YTSDU1
-H 'Authorization: Bearer {access_token}'
response = requests.get(
url=https://api.quantum.moodysanalytics.com//job/W4P3Q4YTSDU1,
headers={"Authorization": "Bearer " + access_token})
This endpoint returns a JSON object like this one, with all the Job deatils:
{
"job": {
"W4P3Q4YTSDU1": {
"status": "PENDING",
"started_at": "08/15/2024, 10:52:45",
"end_at": "",
"executions": {
...
}
}
}
}