Does JS API have a limit to the amount of request it can handle?


(Danny Ngo) #1

Hi,

I’m trying to migrate assets from an old metadata scheme to a new one using the JS API.
So I test this on a branch with less than 10 assets works fine anything over 10 I get ‘nonce token is invalid’
Is there a limit to the amount of request the JS API can handle?

Thanks
Danny


(Bart Banda) #2

Are you doing these in parallel? Or are you doing one after the other?

After you get the nonce token error, are you logged out of Matrix?

Can you share the JS code you are using?


(Danny Ngo) #3

Hi Bart,

I’m doing it in parallel.
No I don’t get logout from Matrix.
So i’m using the batchRequest to retrieve the metadata then create a standard page asset within a loop there a callback method to set the metadata schema and then set the metadata fields.

function matrixGetChildern() {
var parent = document.getElementById(“newrent”).value;

js_api.getChildren({
“asset_id”:“204030”,
“levels”:2,
“type_codes”:[
“page_standard”
],
“link_types”:[
“SQ_LINK_TYPE_1”,
“SQ_LINK_TYPE_2”
],
“get_attributes”:0,
“dataCallback”:getMeta
})
}
function getMeta(object) {
var id;
var sname;
var str = JSON.parse(JSON.stringify(object));
for(var i = 0;i < str.length;i++){
id = str[i].asset_id;
sname = str[i].name;
idArray.push({“id”:str[i].asset_id});

 js_api.batchRequest({

“functions”:{
“0”:{
“function”:“getMetadata”,
“args”:{
“asset_id”:id
},
“blocking”:1
},
“1”:{
“function”:“createAsset”,
“args”:{
“parent_id”:409449,
“type_code”:“page_standard”,
“asset_name”:sname,
“link_type”:1
}
}
},
“dataCallback”:setMeta
});

}

}

function setMeta(o){
//var t = JSON.parse(o);
//alert(t);
var i = o[1].id;
var title = o[0][‘Event.Title’];
var sdate = o[0][‘Event.Start.Date’];
var edate = o[0][‘Event.End.Date’];
var leadtext = o[0][‘Event.Lead.Text’];
var description = o[0][‘Event.Short.Description’];
var pagetype = o[0][‘Page.Type’];
var school = o[0][‘Page.School’];
var location = o[0][‘Event.Venue’];
var disOnHome = o[0][‘Display.On.Homepage’];
var eventAuthor = o[0][‘Event.Author’];
var pageEventType = o[0][‘Page.Event.Type’];
var fsd = formatDate(sdate);
var fed = formatDate(edate);
var fst = formatTime(sdate);
var fet = formatTime(edate);
//alert(i);
/js_api.editMetadataSchema({
“assetid”:i,
“schemaid”:“364176”,
“set”:1,
“granted”:1,
“cascades”:1
});
/
js_api.batchRequest({
“functions”:{
“0”:{
“function”:“editMetadataSchema”,
“args”:{
“asset_id”:i,
“schemaid”:“364176”,
“set”:1,
“granted”:1,
“cascades”:1
},
“blocking”:1
},
“1”:{
“function”:“setMetadataAllFields”,
“args”:{
“asset_id”:i,
“field_info”:{
“364178”:title,
“364184”:leadtext,
“364185”:description,
“10702”:pagetype,
“15953”:school,
“364179”:fsd,
“364180”:fed,
“364183”:location,
“409662”:disOnHome,
“364181”:fst,
“364182”:fet,
“15965”:pageEventType
}
}
}
}
});

}

Thanks

Danny


(Bart Banda) #4

Not sure I understand this part. Can you explain this a bit more in separate steps of what you are trying to do? It’s not obviously clear either from the code. Just in case there might be an easier way to do it.


(Danny Ngo) #5

Hi Bart,

Basically, I’m trying to migrate data from one metadata schema into a new metadata schema, If there a simple way to do this that will be very helpful.

Thanks

Danny


(Bart Banda) #6

So, you want to apply a new metadata shcema to a bunch of assets that have another schema already applied, and remove the old schema but retain some of the fields and their values?

If that’s the case, you could just link those fields from the old schema to the new, apply the new schema, remove the old one. Could run it as a test on a single asset first to make sure it does what you want.


(Danny Ngo) #7

Yes, that the gist of it.

Link? How do I link the old meta schema fields to the new ones?

Thanks

Danny


(Bart Banda) #8

Just like you would link any other asset into to places. Can use the Asset Map to drag and drop the fields under another section in the new schema and choose “Link Here”.