Get job result
get
https://api.playment.io
/v1/projects/:project_id/jobs/:job_id
JOB RESULT
get
https://api.playment.io
/v1/attachments?url=:result_url
ATTACHMENT

Reference python script to get the job result of a batch

1
import requests
2
import json
3
import os
4
import urllib.request
5
x_api_key = ""
6
project_id = ""
7
batch_id = ""
8
9
def get_batch_job(project_id, batch_id, x_api_key,next_page_token):
10
base_url = "https://api.playment.io/v1/projects/{}/batch/{}?page_token={}".format(
11
project_id, batch_id, next_page_token
12
)
13
headers = {"x-api-key": x_api_key}
14
response = requests.get(base_url, headers=headers)
15
# print(response.json())
16
if response.status_code >= 500:
17
raise Exception(response.text)
18
if 400 <= response.status_code < 500:
19
raise Exception(response.text)
20
return response.json()
21
22
def get_job_result(project_id,job_id, x_api_key):
23
base_url = "https://api.playment.io/v1/projects/{}/jobs/{}".format(project_id,job_id)
24
headers = {"x-api-key": x_api_key}
25
response = requests.get(base_url, headers=headers)
26
# print(response.json())
27
if response.status_code >= 500:
28
raise Exception(response.text)
29
if 400 <= response.status_code < 500:
30
raise Exception(response.text)
31
return response.json()
32
33
def get_attachment(result_url, x_api_key):
34
base_url = "https://api.playment.io/v1/attachments?url={}".format(result_url)
35
headers = {"x-api-key": x_api_key}
36
response = requests.get(base_url, headers=headers)
37
# print(response.json())
38
if response.status_code >= 500:
39
raise Exception(response.text)
40
if 400 <= response.status_code < 500:
41
raise Exception(response.text)
42
return response.json()
43
44
if __name__ == "__main__":
45
batch_res = get_batch_job(project_id, batch_id, x_api_key,'')
46
jobs = batch_res['data']['jobs']
47
48
while 'next_page_token' in batch_res['data'].keys():
49
next_page_token = batch_res['data']['next_page_token']
50
batch_res = get_batch_job(project_id, batch_id, x_api_key,next_page_token)
51
jobs = jobs + batch_res['data']['jobs']
52
53
54
# Set the desired folder struture/name here
55
folder_name = batch_id
56
57
for job in jobs:
58
job_res = get_job_result(project_id,job['id'],x_api_key)
59
job_annotation_result = get_attachment(job_res['data']['result'],x_api_key)
60
61
# Set the filename here
62
file_name = job['id'] + '.json'
63
with open(os.path.join(folder_name, file_name),'w') as outfile:
64
json.dump(job_annotation_result, outfile)
65
print(job['id'])
Copied!