Update contacts with python API - batch mode

Hello! :slightly_smiling_face:

I am trying to use the python API to update a set of HS contacts. I am able to do this contact by contact (with a for loop), but I would like to do this in batch mode.
Reading the documentation, I see that the input properties have to be in this format:
inputs=[{“id”:“1”,“properties”:{“company”:“Biglytics”,“email”:“bcooper@biglytics.net”,“firstname”:“Bryan”,“lastname”:“Cooper”,“phone”:“(877) 929-0687”,“website”:“biglytics.net”}}]
and I am wondering if there is a simple way to convert a python dictionary or list to this format? I’ve done something similar with the SimplePublicObjectInput, with something like:
SimplePublicObjectInput(properties=properties_ccontacts[0])
and this creates the formatting needed for the “simple” (not batch) API to work. But I haven’t found in the documentation something similar for the batch api.
Many thanks,
Iván.

Hi @ioteo,

Thank you for reaching out to the Community!

I wonder if @MatthiasWeber & @taran42 could help us out? Thank you! :star:

Cheers
Mia, Community Team

i’m sorry. No knowledge in python. Sorry.

No worries Matthias, thank you for letting me know! :folded_hands:

Hey

not quite sure if I follow you, but there is a class called BatchInputSimplePublicObjectBatchInput that you could use in this scenario, where you can pull in a list of dictionaries into the input. It looks something like this:

updateInputs = BatchInputSimplePublicObjectBatchInput( inputs=[ { “id”: “1”, “properties”: { “company”: “Biglytics”, “email”: “bcooper@biglytics.net”, “firstname”: “Bryan”, “lastname”: “Cooper”, “phone”: “(877) 929-0687”, “website”: “biglytics.net”, }, }, { “id”: “1”, “properties”: { “company”: “Biglytics”, “email”: “bcooper@biglytics.net”, “firstname”: “Bryan”, “lastname”: “Cooper”, “phone”: “(877) 929-0687”, “website”: “biglytics.net”, }, }, ] )

You can then use that as an argument of the request in batch_input_simple_public_object_batch_input like this:

updateContacts = hubspot.crm.contacts.batch_api.update( batch_input_simple_public_object_batch_input=updateInputs )

Sorry about the formatting, but the system won’t let me post with code blocks and proper highlighting.

Maybe you knew this already, so please give some more detail regarding your original question.

But if you found this post helpful, consider helping others in the community to find answers faster by marking this as a solution. I’d really appreciate it.

Cheers,

Chriso

Thank you Chriso! :slightly_smiling_face: