REST Resource Javascript include JSAPI


(Nic Hubbard) #1

Matrix Version: 5.3.1.0

When using the REST Resource Javascript asset, is it possible to somehow include the JS API so that we can use the response from the REST Resource, and then use the JS API to create assets?


(Bart Banda) #2

The JS API works on making HTTP requests to it via POST, which you can’t do server side without doing another REST call.

You would need to do another REST call to the JS API in that case.

So you could use a trigger where the first REST response calls the data and sets it in a session var.
Then the next trigger calls the JS API asset as the same HTTP request that you would do from the front end.

Alternatively just use a trigger to create the asset?


(Nic Hubbard) #3

You mention just having a trigger create the asset, but I feel it would be much more flexible with the JS API. So basically what I want to do is, take the response from the REST response and process that with my own javascript. Based on the response I might want to create some assets or edit some assets.

Is this possible?


(Bart Banda) #4

The only way that would be possible with the JS API is to do another REST call to it. You could try calling the JS API with 1 REST asset using the value of your first one. So make a POST call with your second REST asset looking something like this:

js_api.createAsset({
   "parent_id":100,
   "type_code":"comment",
   "asset_name":"%globals_asset_contents_raw:1234%"
}) 

Where 1234 is the asset ID of your first REST asset.