Question

Using dynamic data in a custom JSON request

  • 29 March 2023
  • 6 replies
  • 563 views

Userlevel 1
Badge

How do you properly pass dynamic data into the JSON body of a custom webhook?

Every time I try, I get an error “We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly.” If I run the scenario and test the input with JSONLint, it comes back as valid JSON. If I copy the JSON without variable data into the webhook body, the action works. 

I have tried using a formatter step to put all of the JSON into one variable that I then pass through. That still does not work. 

Here’s an example, if I type this directly, then the action step works.

{
"model": "gpt-3.5-turbo",
"messages": [{
"role": "user",
"content": "Please draft a concise email. Email Ashley about buying tickets to the conference on Friday."
}],
"temperature": 0.7
}

 

If instead I use a variable, then it doesn’t.

{
"model": "gpt-3.5-turbo",
"messages": [{
"role": "user",
"content": "Please draft a concise email. {{187961999__output}}"
}],
"temperature": 0.7
}

 


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

6 replies

Userlevel 7
Badge +14

Hi @CarlL

Good question.

Is there a reason you are trying to use the OpenAI via a Webhook vs using the OpenAI or ChatGPT Zap apps?

OpenAI: https://zapier.com/apps/openai/integrations#triggers-and-actions

ChatGPT: https://zapier.com/apps/chatgpt/integrations#triggers-and-actions

 

We’d need to see detailed screenshots with how your Zap steps are configured in order to properly review.

Userlevel 1
Badge

No reason more than I should be able to and it’s an example of JSON error I get anytime I use dynamic data in the request, not just for OpenAI. I assume that there’s a method to passing dynamic data into the JSON that I’ve not been able to find. Here are screenshots. One removes new lines so that the text goes into the JSON correctly.

Userlevel 7
Badge +14

@CarlL 

Make sure to remove leading/extra/trailing whitespace in the JSON data.

Userlevel 1
Badge

I’ve done that as well. I can copy the input value from the failed step and check it with JSONLint. It is valid JSON.

Userlevel 7
Badge +14

@CarlL 

I tested successfully with this POST Webhook config.

 

 

Userlevel 1
Badge

What’s the code step you’re using? I had used formatter to remove line breaks of the original input.