REST API get values not working in content section

Hi - I saved a REST API Get request as “getdata”

For a Span tag, in content section,
When I write

return {get(‘data’)->get(‘value’)}
Here: how we should refer which saved REST Api we are calling?

Not returning anything

Even tried
return {getdata->get(‘data’)->get(‘value’) - but no response

Note:
get(‘data’)->get(‘value’)
This returns the right response within the REST API

@divhunter

Why don’t you use the variable popup system for that?
image

From there inside builder, you’ll see your data so you can just select it.

Actually I tried it but it’s not clear.
Do you have any documentation on how to do it?

I saw in your previous document, you have used the content section.

In the formatting price & date section, you have referred

$(value->get(‘price’)
$(page->get(‘data’)

What is the value & page here & where you are defining the REST API name here?

Sorry if I misunderstood your initial question :see_no_evil: but there are a few ways of accessing REST data:

Save your REST response as a variable:

Then all your variables is available in Builder under System->Rest:

You can also access it with:
$rest->get(‘variablename’)
or
return ${rest->get(‘variablename’)}

If you want to access the REST data directly (without saving the response as a variable), set the Source, then you usually use the built in Builder functions, or use:
${value->get(‘fieldname1’)->get(‘fieldname2’)}
or on a single REST data page (a slug for instance) you usually need to use
${page->get(‘fieldname1’)->get(‘fieldname2’)}

There isn’t much clear documentation around this, but ask specific questions here, and the community is most likely able to help you, if we fail, @dejan will most definitely fix it :slight_smile:

1 Like

Hi - Thanks for your update

I’m able to pull the values now.
But I guess everytime only after logout & login the REST api started working. Initially even after I added the rest->get(‘variablename’) , it was not woring. After relogging in it worked, which might have to be fixed.

Thanks for your clarification…!!

You probably need an access token or likely to keep the REST “open”, this can also be done using REST variables and proper set cache (depending on how your request access is configured).

I use this for an “access token” renewed every 15 minutes and feed that token value into each request. Divhunt is virtually limitless on what you can do.

Ex:
Get and set token (See name is set to “#1 xxxx” to make sure this request loads first):

Then access the token in Request Headers for your API (in this case I use “Bearer” for access token value):

2 Likes