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 available via this.request and provides access to the following data:

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

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).

this.request.context.userId

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

this.request.context.userToken

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

this.request.context.userRoles

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

this.request.context.deviceType

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

this.request.headers.<headername>
* Request path - path in the request URL which identifies the invoked method. This is the part of the URL which comes after <service version>:

https://api.backendless.com/<App ID>/<REST API key>/services/<service name>/<service version>/<path from @route>

the value is available by accessing:

this.request.path
* Path parameters - if the code declares a parameterized custom REST route, the parameters can be accessed with the following code:

this.request.pathParams.<parameter name>

for example, for the following parameterized REST route:

@route POST /contacts/{firstname}/{lastname}

and the following request path:

/contacts/Joe/Developer

the service code will receive the following this.request.pathParams object:

"pathParams": {  
    "firstname": "Joe",  
    "lastname": "Developer"  
}
* Query parameters - all parameters for the methods recognized or declared as HTTP GET must be sent in the URL's query string. Service code can use the following API to get access to these parameters:

this.request.queryParams.<param name>