⚙ Operations Hub


Workflow Custom Code POST API - Registered contact in external (3rd party) system

Hi all,


We are premium users of your system and Hubspot's startup program members.

Within our Automation -> Workflow, We are trying to set custom code using an API to one of our partners.

The API simply allows us to registred new users within their system as well.

To complete that; we are using their API, which is a simple POST.
Upon completion, we are getting their status along with the user's registered code.

If case of failure, they simply provide us with a message that contains a ley with the failure reason.


What we would like to achieve:
1. Get the relevant user data from our HubSpot contact list
2. Execute the POST using the contact's data from step 1 above.
3. Upon completion and response from their system (API), update a specific contact's fields which will then help us to decide if and how to proceed with the workflow.


To execute the POST and generate the code for it I have used this online tool, [https://reqbin.com/1ayiqdcg] which the API works perfectly.


Now I need your assistance to integrate our Python code into the Hubspot Custome Code section.

This is the generated code:


import requests
from requests.structures import CaseInsensitiveDict

url = "https://<aaaaaaaa>"

headers = CaseInsensitiveDict()
headers["api-key"] = "<api key>"
headers["Content-Type"] = "application/json"

data = """
"firstName": "<hubspot contact's first name>",
"lastName": "<hubspot contact's last name>",
"email": "<hubspot contact's email>",
"phoneNumber": "<hubspot contact's phone number>",
"abc123": "<hubspot contact's special field A>",
"xyz": "<hubspot contact's special field B>"

resp = requests.post(url, headers=headers, data=data)


 This is the response in case the user successfully generated


"status": "Success", # this value should be placed within our Hubspot contact field 'last-api-status'


"clientId": "62924883f64f63127b90c0ff" # this value should be placed within our hubspot contact field 'last-api-client-id'

This is the response (one of the options) in case the user failed to be generated

"message": {
"key": "backend:alreadyRegistered"
# in this case i'd like to update the contact field 'last-api-status' with the value of "Error"
# and to update the contact field 'api-status-reason' with the value of "alreadyRegistered" (from the key above)
"index": "2"

0 Replies 0

0 Replies

No replies on this post just yet

No one has replied to this post quite yet. Check back soon to see if someone has a solution, or submit your own reply if you know how to help! Karma is real.

Reply to post

Need help replying? Check out our Community Guidelines