00:00
00:00
Newgrounds Background Image Theme

ZickenMieze 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: 03 - Calling Components

Any actions you want to do with the Newgrounds.IO API are done by calling components. A component is simply a server-side method associated with a class. If we wanted to unlock a medal, we would call the "Medal.unlock" component.

Calling components is done using one, or more, "call objects". For simplicity, let's use the "Event.logEvent" component.

{

    "app_id": 'test',

    "session_id": null,

    "call": {

        "component": "Event.logEvent",

        "parameters": {

            "event_name": "test event",

            "host": "www.somesite.com"

        }

    }

}


In this example, you can see our call object has two properties, "component" and "parameters". The "component" property tells the API what class and method to call, and the "parameters" property tells it what parameters to use.

The Newgrounds.IO API will let you call up to 10 components in a single post. This can be done by simply putting your call objects into an array:

{

    "app_id": 'test',

    "session_id": null,

    "call": [

        {

            "component": "Event.logEvent",

            "parameters": {

                "event_name": "test event",

                "host": "www.somesite.com"

            }

        },{

            "component": "Event.logEvent",

            "parameters": {

                "event_name": "test event 2",

                "host": "www.somesite.com"

            }

        }

    ]

}


In the above example we are logging two events, "test event" and "test event 2". You can mix any variety of events into one call as needed.

In cases like the above, when you want to call the same component multiple times, you can also use a single call object, and put your "parameters" objects into an array. The following example will do the exact thing as the example above:

{

    "app_id": 'test',

    "session_id": null,

    "call": {

        "component": "Event.logEvent",

        "parameters": [

            {

                "event_name": "test event",

                "host": "www.somesite.com"

            },{

                "event_name": "test event 2",

                "host": "www.somesite.com"

            }

        ]

    }

}