I am trying to use Batch API to lock (or unlock) a group parts for a specified project. The batch portion does not work. Please help to check if I build the batch in a wrong way.
Reading parts from the project ( beginning and ending portions) works well.
I tried different ways in the batch portion with no luck. Got 500 “An unexpected server error has occurred”.
Here is my code:
importrequests
importjson
auth=('**************', '******************')
base='https://api.polydyne.com/v1'
project=109
lock=True
res=requests.get('{}/projects/{}/award_parts'.format(base, project), auth=auth)
parts=json.loads(res.text)
print('Before:')
forpartinparts:
print('t', part['partId'], part['locked'])
batch= []
forpartinparts:
req= {
"method": 'PATCH',
"resource": '/projects/{}/award_parts/{}'.format(project, part['partId']),
"body": {
"locked": lock
}
}
batch.append(req)
res=requests.post('{}/batch'.format(base), data=json.dumps(batch), auth=auth, headers={'Content-Type': 'application/json'})
res=requests.get('{}/projects/{}/award_parts'.format(base, project), auth=auth)
parts=json.loads(res.text)
print('After:')
forpartinparts:
print('t', part['partId'], part['locked'])
New contributor