APIs & Integrations

SMCNULTY
Participant

POST working in Postman - Need to transfer to Workflow

SOLVE

Good Afternoon,

    I have a post call working in POSTMAN and would like to use a webhook or custom-code solution in a Hubspot workflow. I created the secret using a private app w/limited scope/permissions.

 

I'm not entirely sure what to put in the code section of HS.   My Postman has no auth but 34 headers and a small body.   Below shows the body as JSON and I have options Text/JS/JSON/HTML/XML.  

 

(the working POST in PM is pre-filling a test MS form)

 

SMCNULTY_0-1733945555320.png

 

 

I see that hubspot has two language options of Node.JS 20.x and Python 3.9.     I tried what I thought to be too easy and set my PM bodyto JS and copied the body over to HS but no dice there.

 

I know little about the POST, I actually submitted the MS form in chrome, recorded the action, copied the curl and imported it to PM.  It actually worked first time.

 

Can someone provide some guideance how to get a working POST in PM to work in HS?  Would the HS postman integration help?

 

  

0 Upvotes
1 Accepted solution
zach_threadint
Solution
Guide

POST working in Postman - Need to transfer to Workflow

SOLVE

Hi @SMCNULTY 👋

 

Firstly, if your previous post contains any potentially sensitive information (e.g. an API access token), I'd recommend removing these from the post and, if relevant, rotating the API access token in the external system.

 

Your Python code would need to conform to HubSpot's requirement to use a function ("main") that takes the workflow "event" as an argument. Additionally, I'd recommend trying to widdle that request down to the bare minimum accepted by the external service's API (Microsoft Office Forms?) -- you'd need to review the relevant API docs for this.

 

If you're interested, I'd be happy to offer some additional consultation on this -- feel free to send me a DM and we can pick this up there.

All the best,

Zach

--

Zach Klein
HubSpot Integrations & App Developer
Meanjin / Brisbane, Australia



Say g'day


If my post helped answer your query, please consider marking it as a solution.


View solution in original post

0 Upvotes
6 Replies 6
SMCNULTY
Participant

POST working in Postman - Need to transfer to Workflow

SOLVE

OK interesting thank you. I expect to be making great use of the PM code snippet function as I'm not a

programmer, I just play one on TV. No one else I work with is willing to attempt this.

 

Here is the form that PM automatically fills out already.

Test MS Form 

 

Here is the 'Python - Request' code snippet conversion from my PM POST.  It's resulting in an error which is shown farther below .

 

It should be noted that I am testing it using a ticket but not actually pulling any properties out of the ticket. I hope that's not causing an error. I'm just using the variable properties as working in PM. 

 

SMCNULTY_1-1733948902319.png

 

 

<CODE START>

import requests
import json

url = "https://forms.office.com/formapi/api/9c7d751b-b1a4-4c4a-9343-12b2814ae031/users/1ac24012-92c8-4c38-9..."

payload = json.dumps({
"startDate": "2024-12-11T18:34:46.144Z",
"submitDate": "2024-12-11T18:35:23.546Z",
"answers": "[{\"questionId\":\"r51e5917882df41e4883dfa9c75a732c9\",\"answer1\":\"postfromHStoMSform\"},{\"questionId\":\"rb7515a5f9de649d0a831a0ec26afa9b5\",\"answer1\":\"Yes\"}]"
})
headers = {
'__requestverificationtoken': 'eMT9AdBdgtjEvI9xLbhxLDP4n45Q1q8cCVCtBwjYObj_zb7xQkW-_xVo_twLEoZSxPTFQ8iY3j7iYguUSosDUEcRQv2z2NJu5n92xQfpCr2UxddpwL67FMpsxWB7e_3r6eFPc7msxkKZP8EvUb_ddw2',
'accept': 'application/json',
'accept-language': 'en-US,en;q=0.9',
'authorization': '',
'cache-control': 'no-cache',
'content-type': 'application/json',
'cookie': 'FormsWebSessionId=6b78d1b8-391a-4f43-a685-aa7539e44e92; MUID=372C69E4D2DC65D50C6E7CFDD39F645D; __RequestVerificationToken=_vxG7Zpqz6I_Ry1rrCkRbO0xSvzzf9tjdCNl46c28xfVyc9kTG4l5vM4te81cbi_TCBKF8yfrUVMcZgseLw3OALbCyGNqC14KyueiVgajVI1; AADAuth.forms=eyJ0eXAiOiJKV1QiLCJub25jZSI6Il8yaTd6Q05KaURxYURCbkxXM0pIelZPU2pVZHJmaHkyUXQ1NEh1RXhGODgiLCJyaCI6IjEuQVEwQUczVjluS1N4U2t5VFF4S3lnVXJnTWRKWnBjbXJlaE5QcHUzbjZjVXE3SWNOQU00TkFBLiIsImFsZyI6IlJTMjU2Iiwia2lkIjoienhlZzJXT05wVGt3TjVHbWVZY3VUZHRDNkowIn0.eyJhdWQiOiJjOWE1NTlkMi03YWFiLTRmMTMtYTZlZC1lN2U5YzUyYWVjODciLCJpc3MiOiJodH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tksnbmXYvNWpzgGn-SEuWGQ5U631ZDym-YoNrTIDfg3hvrZ_ejpLPBvuN7ir_5RKB04eO0OfnAH-VIC64MMJOdHRV49b0_NJk4jajaB2J6zAoynEeaE9GnX0lzhcFnvFJ0wTZuz1YbzvezwKv9FRJQVx9D8L4smr381RdDpNoYa1hGYW2C8MwbjpQ3fBdCkvHMeFFXS3CTAsJe09OuUbM7iiRzA4buXvBfp8CvUnTQS2fn8lEiE0wXVk6m2B7ZXVvdnJ64m4mYDyUdwEwwHTRvdOHRjEEjqEHsTRoPCCyYhqijJCvn6uGqSav2gOzlKwhJen1bSGuNRetCx-sCr8oX7LxfSPaQ9C3ActypXhgWg9h5mAKEWqLS-8ynDADovEzcdQ6_A1iHTPRLyexDmFFZzwfKlgX16zq_mwSY7eqPn50AGEJgPGbq3ITyd6MDTfv5EeBKrE_4IZZAXm3aUJQ-nYDAGwy97Ngh93nIxaFuacT2hYN3shu1hXIrw76TggGz3ByK_JZ-Dq83pTf8hxPXLALzhkHjJiVK4Mwqs_Rf_jxWf7GPWOZEX8DZn0hmj9RoABTzaswX7ftBfcIU8EPjTsdhyyyJyMoQv9Yupoe-INQcrfn0a1Oo2p7BoG2wBlnGrFpANuAWLrKKErt7gKVCrUfofG72yiSa681KsLh9uiCCbyscCHmqocO14XrYvVs5HQIACeylWmKG_CVKdMnzAMDGIPvj2rmWsa9ZwlGijCBgDYMERDw1akVlN9ZV3mEMXqnhyxLdXdG2NsU1YqUfYTcRGozZ6T3mu; MicrosoftApplicationsTelemetryDeviceId=822711f4-1aad-42bc-8abf-0fa062e5be32',
'odata-maxverion': '4.0',
'odata-version': '4.0',
'origin': 'https://forms.office.com',
'pragma': 'no-cache',
'priority': 'u=1, i',
'referer': 'https://forms.office.com/Pages/ResponsePage.aspx?id=G3V9nKSxSkyTQxKygUrgMRJAwhrIkjhMmyK_iLScNOJUMFZZ...',
'sec-ch-ua': '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
'x-correlationid': 'cbb1c22f-73d7-443e-9f2d-936c9e057c21',
'x-ms-form-muid': '372C69E4D2DC65D50C6E7CFDD39F645D',
'x-ms-form-request-ring': 'business',
'x-ms-form-request-source': 'ms-formweb',
'x-usersessionid': '844294ea-01a4-412a-94b9-433b030411be'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

 

<CODE END>

 

<ERROR START>

WARNING: The logs for this function have exceeded the 4KB limit.
...
2024-12-11T20:26:02.890Z	undefined	ERROR	Uncaught Exception 	{"errorType":"Runtime.UserCodeSyntaxError","errorMessage":"SyntaxError: Cannot use import statement outside a module","stack":["Runtime.UserCodeSyntaxError: SyntaxError: Cannot use import statement outside a module","    at _loadUserApp (file:///var/runtime/index.mjs:1084:17)","    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)","    at async start (file:///var/runtime/index.mjs:1282:23)","    at async file:///var/runtime/index.mjs:1288:1"]}
INIT_REPORT Init Duration: 178.25 ms	Phase: init	Status: error	Error Type: Runtime.UserCodeSyntaxError
2024-12-11T20:26:04.029Z	undefined	ERROR	Uncaught Exception 	{"errorType":"Runtime.UserCodeSyntaxError","errorMessage":"SyntaxError: Cannot use import statement outside a module","stack":["Runtime.UserCodeSyntaxError: SyntaxError: Cannot use import statement outside a module","    at _loadUserApp (file:///var/runtime/index.mjs:1084:17)","    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)","    at async start (file:///var/runtime/index.mjs:1282:23)","    at async file:///var/runtime/index.mjs:1288:1"]}
INIT_REPORT Init Duration: 1392.40 ms	Phase: invoke	Status: error	Error Type: Runtime.UserCodeSyntaxError
START RequestId: cd443788-5f3e-4145-ba16-cf857d906214 Version: $LATEST

Memory: 65/128 MB
Runtime: 1422.91 ms

<ERROR END>

 

SMCNULTY_2-1733948925771.png

 

0 Upvotes
SMCNULTY
Participant

POST working in Postman - Need to transfer to Workflow

SOLVE

I think the error I posted was wrong. I had HS CC set for JS and not Python.   The error is definitely showing something about MAIN but when I copy/paste it here it will no longer let me post.  So seems that's missing. I will pick away at this a bit, see if I can resolve the error.

zach_threadint
Guide

POST working in Postman - Need to transfer to Workflow

SOLVE

Hi @SMCNULTY 👋

 

Sure thing. If it helps, remember to refer to my original message as a template.

All the best,

Zach

--

Zach Klein
HubSpot Integrations & App Developer
Meanjin / Brisbane, Australia



Say g'day


If my post helped answer your query, please consider marking it as a solution.


0 Upvotes
zach_threadint
Solution
Guide

POST working in Postman - Need to transfer to Workflow

SOLVE

Hi @SMCNULTY 👋

 

Firstly, if your previous post contains any potentially sensitive information (e.g. an API access token), I'd recommend removing these from the post and, if relevant, rotating the API access token in the external system.

 

Your Python code would need to conform to HubSpot's requirement to use a function ("main") that takes the workflow "event" as an argument. Additionally, I'd recommend trying to widdle that request down to the bare minimum accepted by the external service's API (Microsoft Office Forms?) -- you'd need to review the relevant API docs for this.

 

If you're interested, I'd be happy to offer some additional consultation on this -- feel free to send me a DM and we can pick this up there.

All the best,

Zach

--

Zach Klein
HubSpot Integrations & App Developer
Meanjin / Brisbane, Australia



Say g'day


If my post helped answer your query, please consider marking it as a solution.


0 Upvotes
zach_threadint
Guide

POST working in Postman - Need to transfer to Workflow

SOLVE

Whittle* 🤣

All the best,

Zach

--

Zach Klein
HubSpot Integrations & App Developer
Meanjin / Brisbane, Australia



Say g'day


If my post helped answer your query, please consider marking it as a solution.


0 Upvotes
zach_threadint
Guide

POST working in Postman - Need to transfer to Workflow

SOLVE

Hi @SMCNULTY 👋

 

I personally prefer using Python in HubSpot Workflow Custom Code Actions. As such, here's an example using Python's "requests" library that might help you get started:

import requests
import os

def main(event):
  # Use inputs to get data from any action in your workflow and use it in your code instead of having to use the HubSpot API.
  email = event["inputFields"]["email"]
  
  endpoint = "https://webhook.site/abc-123"
  params = {
    "email": email
  }
  headers = {
    "header-x": "abc",
    "header-y": "xyz"
  }
  response = requests.post(endpoint, headers=headers, params=params)
  print(response.status_code)
  print(response.json())
  
  # Return the output data that can be used in later actions in your workflow.
  return {
    "outputFields": {
      "response__status_code": response.status_code,
      "response__body__message": response.json()["message"]
    }
  }

From there, it'll just be a matter of making the necessary updates as per your successful Postman request -- Postman makes this pretty easy via the "Code snippet" > "Python - Requests" translation feature.

 

I hope this proves helpful. Please let me know if you have any follow-up questions.

All the best,

Zach

--

Zach Klein
HubSpot Integrations & App Developer
Meanjin / Brisbane, Australia



Say g'day


If my post helped answer your query, please consider marking it as a solution.


0 Upvotes