Web api will not get values and save as variables

This is my code:

Anybody know why this might be?

All help is much appreciated.

Without seeing what POSTS_API is supposed to be getting, how can we even guess?

i do apologise. here it is

https://donegalnews.com/wp-json/wp/v2/posts?_embed&per_page=10&page=1

it works fine getting the values into a label, just not variable

I cannot find a single instance of “exerpt” in the file.
Is it possible that you are expecting a structure that is not compatible with what you are actually getting?

Which variables did you actually get assigned to a proper value, and which failed?

And how did you determine that the variables were not properly assigned?

i put it into firebase, like imported the json into firebase to get a better view of it. Exerpt works fine though

Its just the variables that are causing the issue

It is spelled “excerpt”.
Your code spells it “exerpt” without the “c”. No wonder you can’t find it.

Your problem is between the keyboard and the chair.

4 Likes

I see that now. I do apologise. Thanks for the help.

And just wondering, dooes web api not work when one of the tags are spelt wrong?

Thanks again.

1 Like

I don’t know.
It should be getting the info in, just that it cannot parse it, and returns empty handed.

If it was me doing that code, I would have gotten the “{get property 0 of object {get object from JSON (response)}}” and assign THAT to a local variable. That way, all the “get properties” are relative to a local variable that does not require multiple transformation – at present, your block is getting it 6 times, essentially doing the same formatting half a dozen times, and throwing all that processing away after extracting a different property; the same as closing a book each time you need to read the next page instead of just turning it.

2 Likes

I am relatively new to this. How would I parse the data. I am unsure what you mean

Have a variable called “propertyzero” that is set to “{get property 0 of object {get object from JSON (response)}}”.

Then each time after you have the sequence "get property whatever “{get property 0 of object {get object from JSON (response)}}” ", you have "get property whatever of “propertyzero”, which already contains the desired subset “property 0”.
For instance, your last assignement block would read

set app data to get property date_gmt of object propertyzero.

You could even make that more efficient still by having an _embedded variable since you are calling this 3 times, or a property0_of_author since you are calling that twice.
The idea is to make the program reuse bits that it already has worked on, instead of always making new ones from scratch.

2 Likes

Okay. If i shared the project with you would you be able to quickly re arrange the blocks for me? sorry for hassling you.

Just one set of blocks and i can do the rest

image

2 Likes

That works great. Thank you!

1 Like