Webhook string problem

Hi,

My webhooks sent a chat message to Discord.

Webhook Body:

{
"username": "SomeUser",
"content": "this is my content"
}

When I try this, everything is ok and Discord shows the message ๐Ÿ™‚

I tried another way because I know that I will use more complex string expressions in the future, using column images, etc.

I used a virtual text column [my string] with this formula expression

 '"content": "this is my content"'

(take attention on my quotation marks)

Then I changed the webhook body to:

{
"username": "SomeUser",
<<[my string]>>
}

When I try this last webhook I receive an error . 

I do not understand why. 

 

0 12 631
12 REPLIES 12

Testing Open AI chat with your question, here's the answer it gave ๐Ÿ˜…:


It looks like the issue is with the way you are using quotation marks in the formula for the virtual text column. In the formula '"content": "this is my content"', the outer quotation marks are single quotes, and the inner quotation marks are double quotes. This can cause a syntax error in the webhook body, because the JSON format uses double quotes for keys and values.

To fix this issue, you can either use double quotes for the entire formula, or you can escape the inner double quotes using a backslash

Hi @Ratatosk 

Yes, I think thay may be that is the problem but I do not know how what to  write in the text.

JSON is key/value pairs.

Do the Key directly in the JSON body, use the column value just for the value part

hi @SkrOYC , like you said, this is a solution, but only if  you do not need a complex construction of the json body.

Imagine this situation . We manage teams and soccer players.

2 tables :Teams and Players 

You have an action "Show Player's  team". You click the action and call the Webhook to send a message to other aplicaction with all the player's names from that team.

For example You need to construct a json body with all the players of "Barcelona Team". It means you will need to use appsheet expressions to construct a json body text. This is my real problem.

 

You can construct a whole JSON object inside a column, but you would need to escape some characters.

And many times it's not even needed to do something like that because that's why there is JSON support and Start: and If: expressions are a thing

hi @SkrOYC  that is my intention !  to make the whole JSON body inside a virtual text column. But I think I have some sintax problem using the quotation marks . That is why a I started with simple appsheet string, before I atack the big problem.

ICYMI, @SkrOYC is referencing that you can directly Use Start expressions in templates and Use If expressions in templates to iterate over rows and conditionally include data.

Hi @Marc_Dillon I tried a [ virtual column ] with the whole json text as @SkrOYC  suggest, using the double double quote and it is very extrange because when I click "Test" in the Expressions Assistant window, I see a perfect JSON string....but still doesn't work  when I put in the Webhook body the expression <<[virtual column]>>

 

 

Appsheet applies a second set of processing to your body text to make sure everything matches up to webhook standards/requirements. Like it puts slashes between everything, or something like that. I think that it's not recognizing your column value as anything other than a simple data value, and as such it isn't applying that second round of processing. So you might have to take that all into account and more deliberately construct the body text in your variable to exactly match how it finally needs to be, from the get go. How do you do that? I don't know, but I'd start with a simple template, and very closely examine the exact body that comes out of Appsheet.

Could you tell us the most complex results you expect so that we can suggest you best practices about it?

Hello @SkrOYC @Marc_Dillon 

I understand what is my problem. I am using images columns. I was trying to send Webhooks to discord including IMAGES.

If I construct the whole JSON body as @SkrOYC said (calculated in a virtual column) , I need to use a PUBLIC URL for the images. 

I tried with public images of my google bucket and it works.

I used the double double quotes as @Marc_Dillon said for the JSON string (virtual column).

Maybe there is another best solution involving the private data. I know that if I write in the Webhook body something like 

"image":  {   "url": "<<[my image]>>"  }

it works well and use a private data, but using concatenates with [my image] to construct the whole JSON does not work.  For the public image I had to convert [my image] (private URL ) in a public URL.

THANKS @SkrOYC @Marc_Dillon for your time.