Hi,
I have a couple of applications which use the JS API to create news items and event entries. These worked fine in versions 4.3 - 4.8. Having upgraded to 4.10 both stopped working. I have re-written them both to work with the enhanced API calls and this all works fine for the news items.
For single calendar events however I am getting Error:Error while created asset and it fails at the first step.
Previous versions of the API had significant amounts of documentation including lists of type_code etc.
a) Is there anything like this for the latest version
B) Anyone have any clue why it should fail for single calendar event but not news item.
TIA
Paul
[quote]
B) Anyone have any clue why it should fail for single calendar event but not news item.
[/quote]
It's not mentioned in the documentation, but the start and end times are required for single calendar events, and will not default to a base value. Don't know if this is your problem, but I've had some issues with creating events which gave a very similar failure message, and which was solved by providing the start/end dates as additional attributes in the createAsset call.
Matthew
Thanks Matthew,
I have the following. Any idea how I should label start_date and end_date in the hash? Format is 2012-10-27 08:00:00
js_api.createAsset({
"key" : jQuery("#key").val(),
"parent_id" : jQuery("#id").val(),
"type_code" : jQuery("#type_code").val(),
"asset_name": jQuery("#asset_name").val(),
"summary": jQuery("#summary").val(),
"body": jQuery("#body").val(),
"start_date": jQuery("#start_date").val(),
"end_date": jQuery("#end_date").val(),
"extra_attributes" : 1,
"link_type" : 1,
"link_value" : "",
"sort_order" : 0,
"is_dependent" : 0,
"is_exclusive" : 0,
"dataCallback" : new_asset_cb
});
OK, this fixed it. Thanks for the pointer.
function get_dates(){ try{ return "start_date=" + jQuery("#start_date").val() + "&end_date=" + jQuery("#end_date").val(); } catch(e){ return ""; } }
function new_asset(){
var options = new Array();
options['key'] = jQuery('#key').val();
var js_api = new Squiz_Matrix_API(options);
js_api.createAsset({
"key" : jQuery("#key").val(),
"parent_id" : jQuery("#id").val(),
"type_code" : jQuery("#type_code").val(),
"asset_name": jQuery("#asset_name").val(),
"summary": jQuery("#summary").val(),
"body": jQuery("#body").val(),
"extra_attributes" : 1,
"attributes" : get_dates(),
"link_type" : 1,
"link_value" : "",
"sort_order" : 0,
"is_dependent" : 0,
"is_exclusive" : 0,
"dataCallback" : new_asset_cb
});
}
[quote]
Previous versions of the API had significant amounts of documentation including lists of type_code etc.
[/quote]
Hi Paul,
Which documentation are you referring to? None has been removed as far as I am aware.
For future reference, a list of type_codes is available within Squiz Matrix, on the Asset Tree screen. Additionally, asset attributes are documented within the relevant manuals (you can view the attributes for Calendar Events at http://manuals.matrix.squizsuite.net/calendar/appendices/asset-attributes).
Feel free to contact me directly if you have any further inquiries.
Ah, thanks Josh this would have proven useful, I wasn't sure what to search for to find it however. I'll make a note for future reference.
The docs I refer to were I think published by the person who developed the API and may not have been on a Squiz site at all now I think about it. This was about 3 years ago. They detailed at a low level how the JS API interacted with the REST API underneath and I bypassed it for most of my calls and did RESTful calls direct with URL parameters. This is why my apps finally broke and had to be written to use the JS API properly.
What you have cited there would have provided all the details I was missing.
Regards
Paul
[quote]
The docs I refer to were I think published by the person who developed the API and may not have been on a Squiz site at all now I think about it. This was about 3 years ago. They detailed at a low level how the JS API interacted with the REST API underneath and I bypassed it for most of my calls and did RESTful calls direct with URL parameters. This is why my apps finally broke and had to be written to use the JS API properly.
[/quote]
Are you talking about me? I wrote the first 2 version of the JS API for Matrix.
It has never (at least not when I wrote it) used the REST API underneath. 
Hi Nic,
Well I was actually just guessing how you did it, but what I mean is I looked at your functions to see what parameters they passed in the URL and then built URLs like and made get and post requests to the JS API asset direct. Nice piece of work by the way.
What did for me was the inclusion of the nonce_token in the _doPost function. It forced me to use the API as an API rather than a sort of RESTful service (where I did my own GET and POST requests rather than using your functions.)
I'm glad of the change to be honest as this nails down the security of everything much better and I was anticipating my rather perverse implementation would bite me back someday.
[quote]
Nice piece of work by the way.
[/quote]
I can really only take credit for the idea and the first 2 versions. It has been completely rewritten and upgraded since then. Squiz has done an amazing job!