Skip to main content

I’m using a webhook that sends a POST to perplexity, and zapier keeps throwing errors when i insert data from another zap.

 

This is what my Code looks like in the Webhooks by Zapier node
And this is the reference to the a previous zap, the dynamic data, that i want to send as data with the webhook.

Again, this is what the full code looks like.

{
  "model": "llama-3.1-sonar-large-128k-online",
  "messages": e
    {
      "role": "system",
      "content": "You're a smart information gathering agent. 
1.##ENSURE YOU PROVIDE LINKS TO WHAT YOU'RE QUOTING AFTER EVERY PARAGRAPH OF YOUR REPORT ANALYSIS ##At the end of your detailed report, make sure to relate it back to the candidate in a summary <i put the dynamic zapier data here>."
    },
    {
      "role": "user",
      "content": "Provide a detailed report on the thing"
    }
  ]
}

The issue is the webhook actually works, provided I don’t input the zapier dynamic data.
The tests run and the api call happens.

But If I do include the dynamic data, I get errors. 

And I don’t get it. It’s sending plain text from openai to perplexity. It shouldn’t be throwing up issues. What’s going wrong?

I’ve changed code from time to time to test different formats but the error is usually a JSON decode error - but my JSON is clearly formatter correctly, no?

{
"error": {
"message": "d\"At body -> 985: JSON decode error\"]",
"type": "bad_request",
"code": 400
}
}

Please help. I’ve thrown this into claude, chatgpt; I’d even throw this into my own mother if she’d throw a solution back.

Hi @dina 

The mapped variable value may need to be encoded for line breaks and special characters.

Tool to check the JSON: https://jsonlint.com/

 



Used Jsonlint to validate this, and it says 

JSON is valid!

unflatten
yes
method
POST
url
https://api.perplexity.ai/chat/completions
data
{
"model": "llama-3.1-sonar-large-128k-online",
"messages":
{
"role": "system",
"content": "You're an intelligent pet adoption history analyzer. 1. Using the information provided from the pet owner, determine and list all animal shelters they adopted from. 2. Research each animal shelter INDIVIDUALLY and provide detailed information, identifying their main focus, what services they offer, what types of animals they cater to, annual adoption rates (actual or estimated, depending on available data), their size, and if they receive any major funding or grants. For some smaller shelters, you may need to search extensively for any available information. ##MAKE SURE TO INCLUDE SOURCES FOR YOUR INFORMATION AFTER EACH PARAGRAPH IN YOUR ANALYSIS REPORT ##At the conclusion of your detailed report, be sure to connect it back to the pet owner in a summary."
},
{
"role": "user",
"content": "Provide a comprehensive report on the animal shelters the following pet owner has adopted from: Alex Rodriguez
Data

Location of adoption
Year of adoption
Home Location:
Country: Not Provided
State: Not Provided
City: Not Provided"
}

"
}
]
}
headers
headers
accept
accept
application/json
content-type
content-type
application/json
Authorization
Authorization
Bearer pplx-000000000000000000000000000000000000

But I still get an error. Above is full code exactly as it would be in the webhook zap.

Failed to create a request in Webhooks by Zapier
>"At body -> 1018: JSON decode error"] (HTTP Status Code: 400)
Click on the Troubleshoot tab below or learn more in our help center.

 


To clarify, I’ve swapped out the data in the above post of the JSON because it’s sensitive data, but claude has messed it up, so it will have errors.

Rest assured, my JSON is correct.


So, the JSON is correct but it’s still giving the same error code.

I don’t why this is marked as solved. It hasn’t been solved.


@dina 

We would need to see updated screenshots with how your Zap step is configured along with the encountered error.

 

For the JSON in your example it is still invalid due to line break not being encoded properly.

 


Here you go. 
 

put lots of 000s for bearer to obscure api key, but the key does work

 


@dina 

Likely same issue with the mapped variable causing the JSON structure to break.

The Full Response variable likely needs to be properly encoded to handle line breaks.

Either instruct ChatGPT to convert line breaks to be encoded for use in a JSON body structure.

Or use a Formatter > Text > Replace step to replace line breaks :newline:] with: \n

 


Thank you, Troy. 
I LOVE YOU, MAN!

YOU SOLVED IT!

That detail you provided in this step was EXACTLY what I needed.
It’s finally working.

😇
<alexa, play the halo theme song>


Realistically, the real issue with my understanding is I’m no programmer, so parsing and line breaks, even though I loosely know what they mean, don’t mean much. 


I loosely know what decoding is because I’m familiar in gpu video decoding terms, for instance.
This was a good learning point; I’ll pay closer attention to the notes by the boxes of the zap nodes.
And hopefully the better language models get released faster than you have to deal with script kiddies like myself deploying more complex code than they can handle.🖖


Hey @dina,

 

It’s fantastic that Troy managed to guide you on the right track and solve your issue with your Zap. If you have further questions or inquiries, please don’t hesitate to contact us. Thank you.


Reply