REST resource asset: dynamic variable within HTTP Request URL?


(Bdebroglio) #1

Hi everyone,

 

I've got a REST resource asset calling the Flickr API to get a list of photos in a Flickr album.

 

Works nicely.

 

But is there a way to re-use one REST resource for getting multiple albums?

 

That is, can you replace the album ID in the HTTP Request URL dynamically?

 

The HTTP Request URL looks like this:

https://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=[KEY]&photoset_id=[album ID]&format=json&nojsoncallback=1

Or will I need to create a new REST resource asset for each Flickr album?


(Joel Porgand) #2

query your asset like http://path.to/rest_asset?albumid=12345

 

then just substitute %globals_get_albumid% into the query string on your rest asset url

 

if you're nesting the rest asset then you can pass the albumid in as one of the nest content options


(Bdebroglio) #3

query your asset like http://path.to/rest_asset?albumid=12345

 

then just substitute %globals_get_albumid% into the query string on your rest asset url

 

if you're nesting the rest asset then you can pass the albumid in as one of the nest content options

Thanks J.P

 

Looking backwards, I have a nested content DIV on the web page ... which calls an Asset Listing Page ... which calls a JSON Data Source ... which calls a REST Resource..

 

Can the variable work its way up that tree?


(Joel Porgand) #4

I think it should? Best bet is to test and see. 

 

If it doesn't I think the mostly likely place you'd run into trouble is on the JSON data source asset. If that's the case you could try specifying the rest asset using a hardcoded URI (and inserting your variable in that using the global keyword) instead of the asset selector.


(Bdebroglio) #5

Easy enough to create the 4 assets for a specific Flickr album, but not having much joy trying to abstract out the process. Any examples out there, apart from what's in the manual?


(Iain Simmons) #6

There's a 'Append Query String' option on the REST Resource asset's details page ('Append query string to the request URL' option on the REST Resource JavaScript details page). If you use that then you should be able to use the URL to your REST Resource with those query strings already added (you'll need to put together all of the variables though).