Trigger event header value in HTTP post request BODY

Hi,

I am trying to reference a value from a webhook trigger event header and pass it onto the body of the HTTP request that I am sending to another application via API call.

Now, when I pass the value, I get an error message saying JSON parsing failed. The reason I see is that the header event path is referenced with double quotes and the BODY of my POST API query is also structured with double quotes. I have tried to replace double quote with single quotes in the body but that still fails.

Is there a possible way to concatenate a value from previous step into the value of the body of HTTP request.

Body for my POST HTTP call

Hi @adil.chughtai,

Yes, you can concatenate a value from a previous step into the body of your HTTP request. To do this, you can use template literals in JavaScript. Here’s an example of how you can modify your code to achieve this:

const body = `{
  "name": "${steps.trigger.event.headers['header-name']}"
}`;

return {
  url: "https://api.example.com/endpoint",
  method: "POST",
  headers: {
    "Content-Type": "application/json"
  },
  body: body
};

In this example, steps.trigger.event.headers['header-name'] is the value from the webhook trigger event header that you want to pass into the body of the HTTP request. By using ${} within the template literal, you can dynamically insert the value into the body string.

Make sure to replace 'header-name' with the actual name of the header you want to reference.

Let me know if this helps!
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double check my answers and code! Learn how to build your own.

Hi,

Thank. I tried adding the first section this script into the code body of the workflow but it fails with the following error.

Thanks

@adil.chughtai,

Could you share the screenshot of you trigger event data?

Hi,

It is just a webhook based trigger… Nothing special in the trigger. What follows is after the webhook trigger is received, HTTP request is sent to another application to take action based on the trigger. Previous levels of filtering is all done and then passing on the values to the body of the HTTP request.

However, I just finally got a way to fix it and that is by creating 3 different code snippets where I get all the description in a simple string field and then return them into another variable and an in the body section i am just adding those return values from those code snippets as well as trigger steps.

This is how it looks like now and it works…

Thanks for the help. I have it figured out with some persistence…