We use cookies to make HubSpot's community a better place. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. To learn more, and to see a full list of cookies we use, check out our Cookie Policy (baked goods not included).
May 13, 2022 5:13 PM
Hey everybody!
This time Im needing a way to change te body request in a post method using workflow weebhook. need to use some properties to build the request boddy and place them in specific named variables.
"chatPlatform": "whatsapp",
"chatChannelNumber": "your_phone",
etc...
Is this possible, been reading for a while a everybody says no and im a quit fear tho hehe
Have a great weekend!!
Solved! Go to Solution.
May 16, 2022 2:16 AM
Hi @rechavar ,
You can not change the post body in a webhook action. You can however use the custom code action with Axios and make a post request that way. This could look something like this:
const axios = require('axios')
exports.main = async (event, callback) => {
const firstname = event.inputFields['firstname']
try {
axios({
method: 'post',
headers: {
'accept': 'application/json',
'content-type': 'application/json',
},
url: '<YOUR-URL>',
data: JSON.stringify({
chatPlatform: 'whatsapp',
chatChannelNumber: 'your_phone'
}),
json: true,
})
.then((response) => {
console.log(response.data)
})
.catch((error) => {
console.log(error)
})
} catch (err) {
console.error(err)
throw err
}
callback({
outputFields: {
firstname: firstname,
},
})
}
May 16, 2022 2:16 AM
Hi @rechavar ,
You can not change the post body in a webhook action. You can however use the custom code action with Axios and make a post request that way. This could look something like this:
const axios = require('axios')
exports.main = async (event, callback) => {
const firstname = event.inputFields['firstname']
try {
axios({
method: 'post',
headers: {
'accept': 'application/json',
'content-type': 'application/json',
},
url: '<YOUR-URL>',
data: JSON.stringify({
chatPlatform: 'whatsapp',
chatChannelNumber: 'your_phone'
}),
json: true,
})
.then((response) => {
console.log(response.data)
})
.catch((error) => {
console.log(error)
})
} catch (err) {
console.error(err)
throw err
}
callback({
outputFields: {
firstname: firstname,
},
})
}