00:00
00:00
Newgrounds Background Image Theme

xochibunsai just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Newgrounds Wiki: 02 - The Output Object

In the previous tutorial, we learned how to send an "input" object. If you followed this example (working demo at https://jsfiddle.net/PsychoGoldfish/w5k55gL9/6/) you should have gotten a response from the server that looks like this:

{

"success": true,

"app_id": "test",

"result": {

"component": "Gateway.getVersion",

"data": {

"success": true,

"version": "3.0.0"

}

}

}


This response is a JSON-encoded "output" object. The first thing to check in this object is the success property. If this is true it means your overall Input object was accepted without error.

This object also contains an app_id property that basically regurgitates your app_id. This can come in handy if you ever have cause to manage multiple app_ids in a single application.

Finally we have the "return" object. This object contains all the data returned by the component you called.

If you were to post a bad input object, the Output object would be a little different. Let's try posting the same packet, but changing our app_id to "oh-noes-this-is-a-bad-app-id".

Now your Output object looks like this:

{

"success": false,

"app_id": "oh-noes-this-is-a-bad-app-id",

"error": {

"message": "Invalid app_id: \"oh-noes-this-is-a-bad-app-id\"",

"code": 200

},

"api_version": "3.0.0",

"help_url": "http:\/\/www.newgrounds.com\/wiki\/creator-resources\/newgrounds-apis\/newgroundsio"

}


As you can see, the success value is false and we now have an "error" object instead of a "return" object. This is why it is always important to check the success value first!

In the event of an error the output object will also tell you the version number of the api gateway and a help_url property that will remind you where this very WIKI can be found.