· 4 years ago · Jun 10, 2021, 08:32 AM
1import requests
2
3"""
4Details for creating JOBS,
5project_id ->> ID of project in which the job will be created
6x_api_key ->> API key for authentication
7work_flow_id ->> The workflow in which the job will be created
8batch_id ->> The batch in which job will be created
9"""
10
11# method that can be used to call the job creation api
12def create_job(project_id, data, x_api_key):
13 base_url = "https://api.playment.io/v0/projects/{}/jobs".format(project_id)
14 headers = {"x-api-key": x_api_key}
15 response = requests.post(base_url, headers=headers, json=data)
16
17 if response.status_code >= 500:
18 raise Exception(response.text)
19 if 400 <= response.status_code < 500:
20 raise Exception(response.text)
21 return response.json()
22
23
24if __name__ == "__main__":
25 # list of frames in a single job
26 image_url = "https://example.com/image_url_1"
27
28 # reference_id should be unique for each job
29 reference_id = "job1"
30
31 project_id = ""
32 x_api_key = ""
33 work_flow_id = ""
34 batch_id = ""
35
36 job_data = {
37 "reference_id": reference_id,
38 "work_flow_id": work_flow_id,
39 "data": {"image_url": image_url},
40 "batch_id": batch_id,
41 }
42
43 response = create_job(project_id=project_id, data=job_data, x_api_key=x_api_key)
44 print(response)
45