Jump to content

How do I set up a Simple REST GET request and store the response in an array?


Karak

Recommended Posts

So I have a simple REST-server running with an endpoint at https://10.0.0.245:7001/prices

The endpoint returns an array of integers that I want to store on the PLC.

I tried the setup in the attached images, but all  I get is a "Invalid path to value" error. (Only attempting to grab and store the first array-item to begin with).

Does anyone know how to solve this?

 

1778071778_Screenshot(7).thumb.png.1af694b9d026834bcab15516463ac718.png

345038416_Screenshot(5).thumb.png.1b80cd94c145e2540453430957804050.png

 

901844235_Screenshot(6).thumb.png.dc9517a1400263818b4c396bb9141d2c.png

 

Link to comment
Share on other sites

  • 2 weeks later...

Hello,

It would help if you upload the json you are trying to parse.

Also currently there is no support for parsing directly into array.

  • You can parse an array member into a tag. 
    That means you can ask for all the array members and fill an array.
  • You can parse the json into a buffer and then do what ever you want with the data.
  • Upvote 2
Link to comment
Share on other sites

I see your json main brackets are [] which means it's an array and not an object. 
It's a special case which requires you to mark the "IsArray" checkbox and choose the "Main Array Index".
In the example below you can see I asked for the second index.
The "Path Preview" is '/' because you ask for values at the first level and they have no key.
The "Main Array Index" tells us which member to take when there is no key given on the first level. 

Your json[ 1 , 2 , 3 , 4 ,5 , ..., 23]

image.png 

What you tried to do is for a json that looks like this:
{
     "level1": [0, 1, 2, 3]
}

And you asked for level1[0] (Your "Path Preview" is /level1[0]/).
That will get you the value 0. (If you json would actully look like this)

Hope this helps.

  • Upvote 2
Link to comment
Share on other sites

Thank you.

I get an error message saying "Response Parameter must have at least one level" when I copy your image, but I got it working by changing the JSON to 

{
     "level1": [0, 1, 2, 3,.....]
}

and using the following parameters:

image.thumb.png.2c96a01802f416bcf446f72deae0c7bc.png

And it works, so I'll do some experimentation from there on the best way to format the JSON.

 

Thank you once again for your help. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...