APIs & Integrations

rechavar
参加者

change body on webhook post method

解決

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!!

0 いいね!
1件の承認済みベストアンサー
Teun
解決策
名誉エキスパート | Diamond Partner
名誉エキスパート | Diamond Partner

change body on webhook post method

解決

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,
    },
  })
}

 



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


元の投稿で解決策を見る

0 いいね!
1件の返信
Teun
解決策
名誉エキスパート | Diamond Partner
名誉エキスパート | Diamond Partner

change body on webhook post method

解決

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,
    },
  })
}

 



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


0 いいね!