JS API createAsset function not working


#1

Hi Guys, 

 

         I am trying to create assets (standard page) using JS API. Basically I took this (Standard Mode) code https://manuals.matrix.squizsuite.net/web-services/chapters/basic-javascript-api-implementation

 

and converted it into something like this ....

<script type="text/javascript" src="./?a=10001"></script>
<script type="text/javascript">
function setApiKey(api_key) 
{
  // Make this into a global variable
  window.api_key = api_key; 

}//end setApiKey

function printObject(object) {
console.log(“Asset created successfully”);
}
// Function to retrieve parent id and file name from URL
function getQueryVariable(variable)
{
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
function matrixCreateAsset() {
var parent = getQueryVariable(“pid”); // Get Parent Id from pid in URL
var type = “standard-page”;
var name = getQueryVariable(“filename”); // Get file name from filename in URL
//var name = “myfile5”;
var val = “some-value”;
console.log(parent,name); // For debugging
createAsset(parent, type, name, 1, val, -1, 0, 0, 0, 0, printObject);
}
setApiKey(123456789);
matrixCreateAsset();
</script>

And then I was hoping that this code will create a "Standard Page" asset by passing "parent id" and "file name" in the URL like this  ....

 

https://mywebsite.com/test-site/create-pages-using-get?pid=51047&filename=myfile7

But nothing is happening, no error, nothing ....

 

console.log is printing correct pid and filename values ....

 

Any help is very appreciated ....

 

Thanks


(Nic Hubbard) #2

Are you sure there are no javascript errors? The JS API always will return something...


(Tim Davison) #3

If there's no javascript errors look at the ajax response body.  Javascript error would imply a syntax issue, but there may be other reasons the API fails.  These are in the response body, not in the console.

 

What I'd also look for in your case is there's a couple of additional settings you have to configure specifically for creating assets.  But like I said, if these are causing the API to fail it will be in the response body.

 

Lastly, make sure you're not inadvertently calling the API cross-domain.  That will fail in the browser, and some browsers are better at reporting it than others (e.g. 'just doing nothing' sounds familiar).


#4

Hi Tim,

 

         Thanks for your reply. The response body returns something weird. I don't understand what it is, but hopefully you or someone else can help ...

 

Here is the response ....

/**/_xdc_._vjrj7i && _xdc_._vjrj7i( [1,null,0] )

Looks like _xdc_._vjrj7i   is a callback parameter.

 

Also, its all on one domain, there is no cross-domain calling.

 

Also, in the response body, under the HEADERS, I see this listed under Request URL

 
https://maps.googleapis.com/maps/api/js/AuthenticationService.Authenticate?1shttps%3A%2F%2Fwww.mydomain.com.au%2Fsite-admin%2Fpaul-test-site%2Fcreate-pages-using-get%3Fpid%3D51047%26filename%3Dmyfile8&callback=_xdc_._vjrj7i&token=61024

Not sure whats going on behind the scenes ?

 

Thanks


(Bart Banda) #5

Hey Paul, I think you mentioned you guys were on a very old version of Matrix with an early version of the JS API. Did you get a chance to test the trigger idea instead we chatted about? 


#6

Thanks Bart, We upgraded yesterday. Doing UAT today. I'll try the trigger approach next week and report back.

 

Cheers ...!