Changing REST Resource asset URL with trigger


(Ryan Archer) #1

Using the REST Resource asset in conjunction with WP REST API WordPresss plugin to get a blog feed from Wordpress site into Squiz via JSON. Works great. However, the blog in questions is a multisite and the feed URL only works on every child site and not the parent site aggregator.

 

I wanted to setup a trigger that would change the REST Resource URL to another child blog feed every week or so, to rotate the content around. Idea is to setup an event for asset status change (put the asset up for review every week). Set the condition to be the Tree location and the asset type.

 

Then set the action to call REST Resource. But I am unsure if this will allow me to override the REST Resource URL that is currently being used to display blog feed.

 

Would it be even possible to do with triggers?


(Bart Banda) #2

Is the change of the URL format in a consistent way? Or does that need to get passed into the Trigger as a dynamic parameter?

Reason I'm asking is that you might be able to have a keyword modifier on the REST URL field that changes depending on some value you can get from another dynamic keyword? 

 

If that doesn't work, you could always source the URL for the REST asset from a metadata field and change that value with the trigger action? 


(Ryan Archer) #3

Thanks for the suggestion Bart. Given the conditions that we actually need to implement to rotate the feed around the various blogs, it's almost easier to schedule a calendar appointment to tell us when to change the feed URL and what to change it to!

 

I did try something else though. In the JSON REST asset, we put in multiple URLs for the JSON feed. Then feed that asset into the JSON Data Source asset - but it causes an error like so:

  Matrix Warning

			<p>Syntax error: JSON data source for WW1 blog (Id: #347036)				<p>&#160;				<p><span style="font-size:14px;"><span style="color:#000000;">And when trying to "View JSON data", the Parsed data array does not show.</span></span>				<p><span style="font-size:14px;"><span style="color:#000000;">Is it actually possible to combine multiple JSON feed URLs successfully? Further down the page, I can see the raw source data OK.</span></span>

(N Wallis) #4

Hi there,

 

I am using a REST Resource Javascript with multiple URLs,  but it only seems to get a response from the first url provided.  I would like to have a master rest resource that I update with additional urls that return json data and parse them with javascript.  Did you have any luck with what you were trying?

 

Cheers.. Nathan


(Ryan Archer) #5

Hi Nathan,

No luck with that one I am afraid. We’ve just accepted that we have to work around this limitation.


(Byrne) #6

@natewallis so you are using

print(_REST.response.body);
try - print(_REST.responses[1].body);
Each subsequent request should be stored in the array.

@coolwebs
you could use the responses array and use javascript to select the URL that you want to print.
BUT keep in mind the page load will slow right down if you are waiting on multiple requests to complete.