· 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 # print(response.json())
18
19 if response.status_code >= 500:
20 raise Exception(response.text)
21 if 400 <= response.status_code < 500:
22 raise Exception(response.text)
23 return response.json()
24
25
26if __name__ == "__main__":
27 # list of frames in a single job
28 image_url = "https://example.com/image_url_1"
29
30 # reference_id should be unique for each job
31 reference_id = "job1"
32
33 project_id = ""
34 x_api_key = ""
35 work_flow_id = ""
36 batch_id = ""
37
38 job_data = {
39 "reference_id": reference_id,
40 "work_flow_id": work_flow_id,
41 "data": {"image_url": image_url},
42 "batch_id": batch_id,
43 }
44
45 response = create_job(project_id=project_id, data=job_data, x_api_key=x_api_key)
46 print(response)
47