pythongoogle-apigoogle-api-clientbulkapiclient

How To Use request_id in Google API apiclient batch callback


I am currently using apiclient, Google API library. Specifically the python one. The documentation is really unclear. I don't know how can I utilize request_id I got from the callback. I mean for this code:

from apiclient.http import BatchHttpRequest

def insert_animal(request_id, response, exception):
  if exception is not None:
    # Do something with the exception
    pass
  else:
    # Do something with the response
    pass

service = build('farm', 'v2')

batch = service.new_batch_http_request(callback=insert_animal)

batch.add(service.animals().insert(name="sheep"))
batch.add(service.animals().insert(name="pig"))
batch.add(service.animals().insert(name="llama"))
batch.execute(http=http)

Can anybody explain the request_id? Is it possible for me to customize the value?


Solution

  • request_id is an integer of the order of when the request was added to the batch request. It starts from 1.

    Although the content is an integer, it's stored as a string. Weird indeed.