Elementary JavaScript API test

I'm trying to use the JavaScript API to set the metadata of product assets (because it seems it can't be done with a trigger). However, I am very much a novice with JavaScript and I can't even get a simple test to work.


I wonder if someone can tell me why the following code fails to update the metadata for the page #24785 and product #20092 assets, even though the setMetaData function does actually get all the way through to running its dataCallback function:


    
<p>
  <a id="setpage" name="setpage" href="#">Set page metadata</a>
</p>
<p>
  <a id="setprod" name="setprod" href="#">Set product metadata</a>
</p>
<div id="testpanel">test: </div>




Thanks.

[quote]
I'm trying to use the JavaScript API to set the metadata of product assets (because it seems it can't be done with a trigger). However, I am very much a novice with JavaScript and I can't even get a simple test to work.



I wonder if someone can tell me why the following code fails to update the metadata for the page #24785 and product #20092 assets, even though the setMetaData function does actually get all the way through to running its dataCallback function:


    
<p>
  <a id="setpage" name="setpage" href="#">Set page metadata</a>
</p>
<p>
  <a id="setprod" name="setprod" href="#">Set product metadata</a>
</p>
<div id="testpanel">test: </div>




Thanks.

[/quote]



Hi Ben,



Probably a stupid question, but have you closed the first <script> tag properly? - <script src="blah" type="blah"></script>



That'd probably break things a bit. Do you have firebug, can you get a response in the console?



Rugi

You are supplying the callback incorrectly (not sure if this is your actual issue, but it's definitely wrong).

    
    setMetadata(20092,223,'tested',function(data){
    if (!data.hasOwnProperty('error')) {
        $('div#testpanel').append('done');
    }// End if
    });

Have you enabled the "Set Metadata" command via the JavaScript API Asset in Matrix? Also are you honouring the Root Node restrictions?

Thanks for all the advice guys.


I have actually correctly closed the first script tag (the code I pasted in my original post was wrong). I have updated my code to include a proper callback function. I have the API asset set up for all commands and have not specified a root node (which I understand means I can apply the API anywhere).



According to the Firebug console:


[quote]{"error":"You do not have permissions to access this asset"}[/quote]



I don't really understand what this means as I certainly do have permission to access the asset (I am a system administrator) and have turned on "Ignore Permissions".

[quote]
Thanks for all the advice guys.



I have actually correctly closed the first script tag (the code I pasted in my original post was wrong). I have updated my code to include a proper callback function. I have the API asset set up for all commands and have not specified a root node (which I understand means I can apply the API anywhere).



According to the Firebug console:







I don't really understand what this means as I certainly do have permission to access the asset (I am a system administrator) and have turned on "Ignore Permissions".

[/quote]



Check your Root Node settings. Does the asset you're trying to modify live under the designated Root Node?

[quote]
Check your Root Node settings. Does the asset you're trying to modify live under the designated Root Node?

[/quote]



Success!



I specified a root node and now it works.



Thank you for that.



Now I have to implement it for real.