Discussions
Calling the job material list via API (Python/Zapier)
Hi there,
I have a zapier integration that is meant to be calling the job materials list from servicem8 when a job gets assigned to a specific que. I can trigger the action when the job lands in the que and pass it along to my python script which is meant to provide a line item array of all the materials filtered by the uuid of the job which triggered my zap.
I am able to return only the first entry in the material list. Any idea why the rest of the array is being truncated?
e.g my python script:
import requests
# 'jobuuid' is the field containing the UUID in the input_data
job_uuid = input_data['jobuuid']
url = f"https://api.servicem8.com/api_1.0/jobmaterial.json?%24filter=job_uuid eq {job_uuid}"
headers = {
"accept": "application/json",
"authorization": "Basic MYCREDENTIALS"
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
materials_data = response.json()
# Return the materials_data to pass it to the next steps in Zap
return materials_data
else:
return {
"error": f"Request failed with status code: {response.status_code}"
}
This is my return:
uuid: ccec4318-0077-4082-a309-410abb46e9c5
tax_rate_uuid: da374289-575b-4e78-bb6a-1de9409945cb
quantity: 1.0000
name: Bunnings inv. 2016/90315302
price: 61.9800
active: 1
displayed_amount_is_tax_inclusive: 1
displayed_amount: 61.9800
edit_date: 2023-09-19 14:42:36
job_uuid: 5d88a6c0-05c7-434e-86ef-200d2f1ffd6b
material_uuid: 16434f99-94d1-408c-aadb-f7337fcddc3b
sort_order: 0
cost: 56.3455
displayed_cost: 61.9800
id: RqNp2R6aEc50ExK10lucvpcXishvE2A5
runtime_meta
memory_used_mb: 47
duration_ms: 710
logs
I was expecting a json array to be returned however I am only getting which ever material is at the top of the list.
Really hoping I can generate the full list, would have really useful stock reordering applications.
Thanks for any help!
Nate