Skip to content

Invocation Context

The Backendless container which hosts and runs the services code provides a special object for every method invocation. The object is an instance of the com.backendless.servercode.InvocationContext class and provides access to the following data:

  • Application ID - id of the application in which context the method is invoked.

    String applicationId = InvocationContext.getAppId();

  • User ID - objectId of the currently logged in user whose identity is used to invoke the method. A value for this parameter is not present if there is no logged in user (or if the user-token header is not passed for the REST invocations).

    String userObjectId = InvocationContext.getUserId();

  • User token - value of the user-token header sent by the client application when invoking the service.

    String userToken = InvocationContext.getUserToken();

  • User roles - an array of the role names of the logged-in user (if any) who made the API call.


  • Device type - the type of the device which initiated the method invocation.

    DeviceType deviceType = InvocationContext.getUserId();
    // get device type corresponding to the API Key. Possible values are:
    // "IOS", "ANDROID", "JS", "REST", "BL" (business logic)
    String deviceTypeName =;
    // get role name corresponding to the API key. Possible values are:
    // "IOSUser", "AndroidUser", "JSUser", "RestUser", "ServerCodeUser"
    String deviceTypeRoleName = deviceType.getRoleName();

  • HTTP headers - HTTP headers sent by the client application when invoking the service.

    Map<String, String> httpHeaders = InvocationContext.getHttpHeaders();