# Get job result

## JOB RESULT

<mark style="color:blue;">`GET`</mark> `https://api.playment.io/v1/projects/:project_id/jobs/:job_id`

This endpoint allows you to get the annotations created on a job.

#### Path Parameters

| Name        | Type   | Description                                                                              |
| ----------- | ------ | ---------------------------------------------------------------------------------------- |
| job\_id     | string | ID of the job. You would have received this ID in the response when you created the job. |
| project\_id | string | ID of the project where the job was created                                              |

#### Headers

| Name      | Type   | Description                |
| --------- | ------ | -------------------------- |
| x-api-key | string | API key for authentication |

{% tabs %}
{% tab title="200 Job results successfully retrieved." %}

```javascript
{
    "data": {
        "project_id": "905ea3ee-6f62-4bb7-8c31-471e486d9202",
        "reference_id": "001",
        "job_id": "3f3e8675-ca69-46d7-aa34-96f90fcbb732",
        "batch_id": "468b6ae3-e98d-4d08-9427-b6e7a016054c",
        "status": "completed",
        "work_flow_id": "51bb440c-f0ed-4286-8984-ea399cbc1f9w",
        "priority_weight": 5,
        "tag": "2aae1234-acac-1234-eeff-12a22a237bbc", //tag is the workflow_id for the job  
        "result": "https://playment-data-uploads.s3.ap-south-1.amazonaws.com/sample-result.json"
    },
    "success": true
}
```

{% endtab %}
{% endtabs %}

## ATTACHMENT

<mark style="color:blue;">`GET`</mark> `https://api.playment.io/v1/attachments?url=:result_url`

The *result\_url* (`data.result`) returned by the GET Job result API is a private URL (Well, it's public till 15th July 2021, after which we'll enforce it to be private). You need to use this Attachment access API to securely fetch the results. Please refer to the Attachment Access API document for more detail.&#x20;

#### Path Parameters

| Name        | Type   | Description                                   |
| ----------- | ------ | --------------------------------------------- |
| result\_url | string | Result URL returned by the GET job result API |

#### Headers

| Name      | Type   | Description                |
| --------- | ------ | -------------------------- |
| x-api-key | string | API key for authentication |

{% tabs %}
{% tab title="200 " %}

```
The API will redirect to a signed URL of the attachment
```

{% endtab %}
{% endtabs %}

#### Reference python script to get the job result of a batch

```python
import requests
import json
import os
import urllib.request
x_api_key = ""
project_id = ""
batch_id = ""

def get_batch_job(project_id, batch_id, x_api_key,next_page_token):
    base_url = "https://api.playment.io/v1/projects/{}/batch/{}?page_token={}".format(
        project_id, batch_id, next_page_token
    )
    headers = {"x-api-key": x_api_key}
    response = requests.get(base_url, headers=headers)
    # print(response.json())
    if response.status_code >= 500:
        raise Exception(response.text)
    if 400 <= response.status_code < 500:
        raise Exception(response.text)
    return response.json()

def get_job_result(project_id,job_id, x_api_key):
    base_url = "https://api.playment.io/v1/projects/{}/jobs/{}".format(project_id,job_id)
    headers = {"x-api-key": x_api_key}
    response = requests.get(base_url, headers=headers)
    # print(response.json())
    if response.status_code >= 500:
        raise Exception(response.text)
    if 400 <= response.status_code < 500:
        raise Exception(response.text)
    return response.json()

def get_attachment(result_url, x_api_key):
    base_url = "https://api.playment.io/v1/attachments?url={}".format(result_url)
    headers = {"x-api-key": x_api_key}
    response = requests.get(base_url, headers=headers)
    # print(response.json())
    if response.status_code >= 500:
        raise Exception(response.text)
    if 400 <= response.status_code < 500:
        raise Exception(response.text)
    return response.json()

if __name__ == "__main__":
    batch_res = get_batch_job(project_id, batch_id, x_api_key,'')
    jobs = batch_res['data']['jobs']

    while 'next_page_token' in batch_res['data'].keys():
        next_page_token = batch_res['data']['next_page_token']
        batch_res = get_batch_job(project_id, batch_id, x_api_key,next_page_token)
        jobs = jobs + batch_res['data']['jobs']


    # Set the desired folder struture/name here
    folder_name = batch_id

    for job in jobs:
        job_res = get_job_result(project_id,job['id'],x_api_key)
        job_annotation_result = get_attachment(job_res['data']['result'],x_api_key)

        # Set the filename here
        file_name = job['id'] + '.json'
        with open(os.path.join(folder_name, file_name),'w') as outfile:
            json.dump(job_annotation_result, outfile)
        print(job['id'])
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://annotationdocs.telusinternational.com/basic-operations/get-job-results.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
