EN IT
Open2b version 7.8

Admin.api and apiVersion

Admin.api(method, request, function(response) { … })

Calls an API method and returns the response.

Parameter Description
method Full method name.
request Request with method parameters. Use null if no parameters are present.
response Method response.

API calls from JavaScript are asynchronous, meaning Admin.api() returns immediately and the callback (the function passed as the third parameter) is invoked later when the method call completes. You can make multiple calls one after another without waiting for previous ones to finish, because Open2b queues and executes them in order.

If the response and outcome are not important, you can omit the callback.

Example

The following is an example JavaScript call to the commerce.products.update method to update a product:

Admin.api('commerce.products.update', {
    id : 496,
    product : {
        isVisible: true,
        name: { it: 'Nuovo nome', en: 'New name' },
    }
}, function(response) {
    if ( response.status != 'ok' ) { alert('Error: '+response.error.description); return; }
    // done
});

Admin.apiVersion

The Admin.apiVersion function is a variant of Admin.api that, unlike the latter, lets you specify the API version to call. Admin.api instead always calls version 3, which is currently the latest.

Note: it is recommended to use Admin.api. The Admin.apiVersion function should be used only if you need to use different API versions within the same app.

Admin.apiVersion(version, method, request, function(response) { … })

Parameter Description
version API version to call. Call Admin.getInfo for available versions.
method Full method name.
request Request with method parameters. Use null if no parameters are present.
response Method response.

For more details, see the documentation for Admin.api.