Post

1 follower Follow
0
Avatar

Returning just the Guids via the API

Hey, been playing with the Sandbox API, and I really do appreciate it.

Managed to get the data (Product information), great... and in either XML or JSON format... great (so far, I have not really strayed from the Sandbox Javascript implementations).

Can anyone suggest a good way to return, for example, just the ProductCode and the Guid? Rather than all the other product info.

Also - since the Guid is such an **important** item, for the API and other parts of Unleashed - why isn't it made more of? You can't get the Guid from the Unleashed web gui - as far as I can tell.

Philip Ryan

Please sign in to leave a comment.

2 comments

0
Avatar

By usefully using the `JSON.stringify` function, I was able to limit the response to just the ProductCode and Guid, i.e. changing this

    $("#txtSandBoxAPIResults").val("Time taken: " + timeTaken + " seconds. \r\n \r\n \r\n" + JSON.stringify(tmpHTML, false, 2));

to this

    $("#txtSandBoxAPIResults").val("Time taken: " + timeTaken + " seconds. \r\n \r\n \r\n" + JSON.stringify(tmpHTML, ['Items','ProductCode','Guid'], 2));

This is where the second param of `stringify` is the replacer param, and it can be a function or an array. If an array, it ends up being the array of JSON properties that you are interested in. You have to include the top-level property that a given property is part of, so in this case, it's the `Items` property.

Philip Ryan 0 votes
Comment actions Permalink
0
Avatar

Should have used the paragraph styles ...

$("#txtSandBoxAPIResults").val("Time taken: " + timeTaken + " seconds. \r\n \r\n \r\n" + JSON.stringify(tmpHTML, ['Items','ProductCode','Guid'], 2));

Got me this sort of result

{
"Items": [
{
"ProductCode": "[FRED]",
"Guid": "6f405234-b14f-46e6-a69c-53a06301d5df"
},
Philip Ryan 0 votes
Comment actions Permalink