May 28, 2022 12:49 PM
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:
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
# 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)