Sending POST with JSON array


#1

1) Give a description of the problem
Trying to make a POST web request with JSON array. Would like to know how do i set this up in webCoRE. Trying to send this url to my web server -
URL: http://1.1.1.1:3000/device/1234abcd/playMedia/
DATA: [{“mediaTitle”:“Hello world”, “mediaSubtitle”:“Audio notification”, “mediaImageUrl”: “http://example.com/image.jpg”, “GoogleTTS”:“en-US”}]

I have tried with this piston -

As expected, it is sending the variables as an object, but need it to be in an array [].

How do i do this?


#2

As far as I know, we cannot choose an array on GET or POSTS, but I have found a loophole that works well for me. You can make a new variable directly in the format you want:

The variable ‘data’ returns:
“mediaTitle”:“Hello everyone”, “mediaSubtitle”:“Audio notification”, “mediaImageUrl”: “https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png”, “GoogleTTS”:“en-US”


#3

An alternative workaround is you can do 95% of the code in arrays, then right before you do your GET request, you dump the array into a string variable, and send THAT.

(Although I think this method looses the quotation marks)

In this example, the variable ‘data’ returns:
[mediaImageUrl:https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png, mediaTitle:Hello everyone, mediaSubtitle:Audio notification, googleTTS:en-US]


#4

Hi, tried both and was not able to get to work. The problem is that an object must be in the array which is something like [{“a”:“1”,“b”:“2”}].

This is the snippet from Postman that works…now just need how to get that over on webCoRE :slight_smile:


#5

Short answer is that I don’t think you can.

As long as it is a simple {“var1”:“value1”,“var2”:“value2”} structure, it’s fine. But you do not have enough control over sending exact JSON strings to do what you want. Same reason there is no way to send a set of values for a tag wrapped in brackets. Can’t do this:
{“dashboardId”:2,“isRegion”:true,“text”:“House is Unoccupied”,“panelId”:1,“time”:1516882800,“timeEnd”:1516883200,“tags”:"[“Occupancy”]"}


#6

That was what i thought. Was just hopeful that somebody around here has figured out how to do this.


#7

Hmmmm try using html code for the symbols

Here is an example expression

Where there is a will there is a way!


#8

Aww phewey. Both of my methods above work when sending to a private PHP file that I control.

@Gopack2’s workaround above looks promising… I was about to consider escape characters


#9

I tried a lot of different things, always checking with Postman what was REALLY sent. No matter what your value, expression or variable, it’ll be wrapped in curly braces when sent as POST JSON. Not going to be able to get it wrapped on the outside in square brackets (like kayvint needs) in the current implementation of WebCore, even if your expression shows exactly what you want to send. Need some changes like allow more flexibility and the ability to send exact JSON.


#10

What if you complie the string the way you want and send it off to IFTTT webhooks to do the post?


#11

Going to give your method a try - worth a shot. As for doing it through ifttt, will try that and hopefully the delay is not too huge.

This is to the cast-web app to send notifications to my google home speakers. So the ‘text’ portion is the variable bit.


#12

Hello kayvint,

can you detail how you have resolved the problem?

I have the same situation using postman all go well, but using webcore the problem persist.

How you have resolved using IFTTT?


Using IFTTT for POST Json request to web-cast service
#13

I can’t say that i remember it that well, as it was more of a “hack” and was ok if it was not a time sensitive piston.

Over in IFTTT, under the Body field, put in your array…something like this - {“month”:"{{TextField}}", “day”:"{{NumberField}}"}.

And if i’m not mistaken, from your piston, you send an IFTTT maker event with the variables you would want to originally send through.

Hope that helps.