NAV

Overview

Core Operationalization APIs

Integration technology for deploying R analytics inside web, desktop, mobile, and dashboard applications as well as backend systems. Turn your R scripts into analytics web services, so R code can be easily executed by applications running on a secure server.

The core R Server operationalization APIs can be grouped into several categories, including: Authentication, Web Services, Sessions, Snapshots, and Status.

External Documentation

Back to MSDN documentation

Version information

Version : 9.0.1

License information

License : Copyright (C) Microsoft Corporation. All rights reserved.

Swagger

Download the swagger spec file for these APIs

URI scheme

Schemes: http, https

Consumes

Produces

Authentication APIs

The `authentication` APIs provide authentication related operations and access workflow features.

All operationalization API calls must be authenticated using the `POST /login` API or through Azure Active Directory.

If you use the `POST /login` API, R Server will issue you a bearer/access token. This bearer token is a lightweight security token that grants the “bearer” access to a protected resource, in this case, R Server's core operationalization APIs. Once a user has been authenticated, the application must validate the user’s bearer token to ensure that authentication was successful for the intended parties. If your organization uses Azure Active Directory, then AAD will issue the token.

Login User

Path

POST /login

Description

Logs the user in

Example Request

{
    "username": "string",
    "password": "string"
}

Example Response "application/json"

{
    "token_type": "Bearer",
    "access_token": "eyJhbGciOiJSUzUxMiIsInR5cC",
    "expires_in": 3600,
    "expires_on": 1479664807,
    "refresh_token": "ScW2tnhl4Oi7ksHLj/TI"
}

Method

POST

Parameters

Type Name Description Schema
body loginRequest
required
Login properties for athentication LoginRequest

Responses

HTTP Codes Description Schema
200 OK AccessTokenResponse

Errors

Refresh User Access Token

Path

POST /login/refreshToken

Description

The user renews access token and refresh token.

Example Request

{
    "refreshToken": "string"
}

Example Response "application/json"

{
    "token_type": "Bearer",
    "access_token": "eyJhbGciOiJSUzUxMiIsInR5cC",
    "expires_in": 3600,
    "expires_on": 1479664807,
    "refresh_token": "ScW2tnhl4Oi7ksHLj/TI"
}

Method

POST

Parameters

Type Name Description Schema
body renewTokenRequest
required
Renew access token properties for athentication RenewTokenRequest

Responses

HTTP Codes Description Schema
200 OK AccessTokenResponse

Errors

Delete User Access Token

Path

DELETE /login/refreshToken

Description

The user revokes a refresh token.

Example Response "application/json"

{
    "token_type": "Bearer",
    "access_token": "eyJhbGciOiJSUzUxMiIsInR5cC",
    "expires_in": 3600,
    "expires_on": 1479664807,
    "refresh_token": "ScW2tnhl4Oi7ksHLj/TI"
}

Method

DELETE

Parameters

Type Name Description Schema
query refreshToken
required
The refresh token to be revoked string

Responses

HTTP Codes Description Schema
200 OK AccessTokenResponse

Errors

Services Management APIs

The core Web Services APIs facilitate the publishing and management of user-defined analytic web services, including:

Note: For service consumption, please see the `/api` APIs

An R Server web service is a stateless execution in an R shell on the compute node. Each web service is uniquely defined by a `name` and `version` for easy service consumption and meaningful machine-readable discovery approaches.

These RESTful APIs for web services provide programmatic access to a service's lifecycle. The APIs are straightforward, easy-to-use, and when composed together, can form the foundation for more expressive operations.

Web services can be versioned to improve the release of services for service authors and make it easier for consumers to identify the services they are calling. Service versioning is an important part of the publishing process and is designed to be flexible without naming restrictions. We highly recommend the adoption of meaningful and standard versioning conventions such as semantic versioning.

If a web service is published without a version `GET /services/{name}`, a Globally Unique Identifier (GUID) will be created as a unique reference number to represent a version. Since the GUID is not a meaningful version number, the intention is allow an author to treat the service as a development version (seen only by the author) until it is ready to be promoted and shared. From there, a more meaningful version number can be chosen during service publishing to represent a stable release.

Whenever a web service is published `POST /services/{name}/{version}`, an endpoint is registered `/api/{name}/{version}`, which in turn triggers the generation of a custom Swagger-based JSON file. Learn more about consuming web services.

If you use a snapshot when developing your web service, the session snapshot information will be baked into the service API when published and available to any authenticated user consuming that web service later.

Please note that while only the web service author can update, publish, or delete a service, any authenticated user can retrieve a list of services or consume a service.

Get Services

Path

GET /services

Description

Lists all the published services.

Example Response "application/json"

[
    {
        "creationTime": "2016-11-20T18:15:09.917656",
        "name": "addition",
        "version": "v1.0.0",
        "description": "Addition Service",
        "code": "result <- x + y",
        "snapshotId": "8fac71e8-92a9-4959-a679-4376e5aab20d",
        "owner": "deployruser",
        "operationId": "add",
        "inputParameterDefinitions": [
            {
                "name": "x",
                "type": "numeric"
            },
            {
                "name": "y",
                "type": "numeric"
            }
        ],
        "outputParameterDefinitions": [
            {
                "name": "result",
                "type": "numeric"
            }
        ]
    }
]

Method

GET

Responses

HTTP Codes Description Schema
200 OK [ WebService ]

Errors

Create Service by name

Path

POST /services/{name}

Description

Publish the web services for the logged in user with given name and a unique version.

Example Request

{
    "snapshotId": "string",
    "code": "string",
    "description": "string",
    "operationId": "string",
    "inputParameterDefinitions": [
        "array"
    ],
    "outputParameterDefinitions": [
        "array"
    ]
}

Method

POST

Parameters

Type Name Description Schema
path name
required
name of the published web service. string
body publishRequest
required
Publish Web Service request details. PublishWebServiceRequest

Responses

HTTP Codes Description Schema
201 Created string

Errors

Get Service by name

Path

GET /services/{name}

Description

Lists all the published services with the provided name.

Example Response "application/json"

[
    {
        "creationTime": "2016-11-20T18:15:09.917656",
        "name": "addition",
        "version": "v1.0.0",
        "description": "Addition Service",
        "code": "result <- x + y",
        "snapshotId": "8fac71e8-92a9-4959-a679-4376e5aab20d",
        "owner": "deployruser",
        "operationId": "add",
        "inputParameterDefinitions": [
            {
                "name": "x",
                "type": "numeric"
            },
            {
                "name": "y",
                "type": "numeric"
            }
        ],
        "outputParameterDefinitions": [
            {
                "name": "result",
                "type": "numeric"
            }
        ]
    }
]

Method

GET

Parameters

Type Name Description Schema
path name
required
name of the published web service. string

Responses

HTTP Codes Description Schema
200 OK [ WebService ]

Errors

Create Service by name and version

Path

POST /services/{name}/{version}

Description

Publish the web service for the logged in user with given name and version.

Example Request

{
    "snapshotId": "string",
    "code": "string",
    "description": "string",
    "operationId": "string",
    "inputParameterDefinitions": [
        "array"
    ],
    "outputParameterDefinitions": [
        "array"
    ]
}

Method

POST

Parameters

Type Name Description Schema
path name
required
name of the published web service string
path version
required
version of the published web service. string
body publishRequest
required
Publish Service request details. PublishWebServiceRequest

Responses

HTTP Codes Description Schema
201 Created string

Errors

Patch Service

Path

PATCH /services/{name}/{version}

Description

Updates the published service.

Example Request

{
    "snapshotId": "string",
    "code": "string",
    "description": "string",
    "operationId": "string",
    "inputParameterDefinitions": [
        "array"
    ],
    "outputParameterDefinitions": [
        "array"
    ]
}

Method

PATCH

Parameters

Type Name Description Schema
path name
required
name of the published web service string
path version
required
version of the published web service string
body patchRequest
required
Publish Web Service request details. PublishWebServiceRequest

Responses

HTTP Codes Description Schema
200 OK string

Errors

Get Service by name and version

Path

GET /services/{name}/{version}

Description

Lists all the published services with the provided name and version.

Example Response "application/json"

{
    "creationTime": "2016-11-20T18:15:09.917656",
    "name": "addition",
    "version": "v1.0.0",
    "description": "Addition Service",
    "code": "result <- x + y",
    "snapshotId": "8fac71e8-92a9-4959-a679-4376e5aab20d",
    "owner": "deployruser",
    "operationId": "add",
    "inputParameterDefinitions": [
        {
            "name": "x",
            "type": "numeric"
        },
        {
            "name": "y",
            "type": "numeric"
        }
    ],
    "outputParameterDefinitions": [
        {
            "name": "result",
            "type": "numeric"
        }
    ]
}

Method

GET

Parameters

Type Name Description Schema
path name
required
name of the published web service string
path version
required
version of the published web service string

Responses

HTTP Codes Description Schema
200 OK [ WebService ]

Errors

Delete Service

Path

DELETE /services/{name}/{version}

Description

Deletes the published web service for the logged in user.

Method

DELETE

Parameters

Type Name Description Schema
path name
required
name of the published web service string
path version
required
version of the published web service string

Responses

HTTP Codes Description Schema
200 OK N/A

Errors

Service Consumption APIs

The `service api` APIs provide operations for obtaining the `swagger` service holding and capabilities for a specific published web service. From this, analytic web service consumption can take place.

Get API Swagger

Path

GET /api/{name}/{version}/swagger.json

Description

Returns a Swagger swagger.json describing a published web service's API capabilities.

Example Response "application/json"

{
    "swagger": "2.0"
}

Method

GET

Parameters

Type Name Description Schema
path name
required
name of the published web service. string
path version
required
version of the published web service. string

Responses

HTTP Codes Description Schema
200 OK SwaggerJsonResponse

Errors

Session APIs

The `sessions` APIs provide functionality for R session management, which can be divided into the following groups:

A session is an interactive stateful R session that is run in an R shell on the compute node. A session is managed by R Server on behalf of the application.

Create Session

Path

POST /sessions

Description

Create a new session.

Example Request

{
    "name": "string",
    "snapshotId": "string"
}

Example Response "application/json"

{
    "sessionId": "85b1ecd8-f5a5-42ce-87f3-5b7be97665ae"
}

Method

POST

Parameters

Type Name Description Schema
body createSessionRequest
required
Properties of the new session. CreateSessionRequest

Responses

HTTP Codes Description Schema
201 Normal case returns the id of the newly created session CreateSessionResponse

Errors

Get Sessions

Path

GET /sessions

Description

Lists all existing sessions for the current user.

Example Response "application/json"

[
    {
        "id": "e052a7f7-8fcd-40b9-b9b8-d351acd44444",
        "name": "mPheQrfoO0LmbLZ",
        "owner": "deployruser"
    },
    {
        "id": "l0dfsddf-4gjd-40b9-b9b8-sdf98yh99999",
        "name": "mPheQrfoO0LmbLZ",
        "owner": "sean"
    }
]

Method

GET

Responses

HTTP Codes Description Schema
200 The sessions for the current user. [ Session ]

Errors

Delete Session

Path

DELETE /sessions/{id}

Description

Close a session and releases all it's associated resources.

Method

DELETE

Parameters

Type Name Description Schema
path id
required
Id of the session to close. string

Responses

HTTP Codes Description Schema
200 OK string

Errors

Delete Session by force

Path

DELETE /sessions/{id}/force

Description

Aattempt to forcefully close a session and releases all it's associated resources

Method

DELETE

Parameters

Type Name Description Schema
path id
required
Id of the session to close. string

Responses

HTTP Codes Description Schema
200 OK string

Errors

Get Console Output

Path

GET /sessions/{id}/console-output

Description

Returns the console output for the current or last execution

Example Response "application/json"

{
    "consoleOutput": "[1] 5\r\n"
}

Method

GET

Parameters

Type Name Description Schema
path id
required
Id of the session. string

Responses

HTTP Codes Description Schema
200 OK ConsoleOutputResponse

Errors

Get History

Path

GET /sessions/{id}/history

Description

Lists all history for a specific session

Example Response "application/json"

[
    "model <- glm(formula = am ~ hp + wt, data = mtcars, family = binomial)",
    "manualTransmission <- function(hp, wt) { \r\n newdata <- data.frame(hp = hp, wt = wt) \r\npredict(model, newdata, type = \"response\") \r\n}",
    "print(manualTransmission(120, 2.8))"
]

Method

GET

Parameters

Type Name Description Schema
path id
required
Id of the session. string

Responses

HTTP Codes Description Schema
200 OK [ string ]

Errors

Load File

Path

POST /sessions/{id}/files

Description

Loads a file into the R session working directory. The uploaded file name is extracted from the file and if another file with the same name already exists in the working directory, the file will be overwritten.

Method

POST

Parameters

Type Name Description Schema
path id
required
Id of the session. string
formData file
required
The file to be uploaded to the workspace. file

Responses

HTTP Codes Description Schema
201 Created N/A

Errors

Consumes

Produces

Get Files

Path

GET /sessions/{id}/files

Description

Lists all files of a specific session

Example Response "application/json"

[
    "statscore.csv",
    "hist.png",
    "notes.Rmd"
]

Method

GET

Parameters

Type Name Description Schema
path id
required
Id of the session. string

Responses

HTTP Codes Description Schema
200 OK [ string ]

Errors

Get File

Path

GET /sessions/{id}/files/{fileName}

Description

Downloads a file from a session as stream.

Method

GET

Parameters

Type Name Description Schema
path id
required
Id of the session. string
path fileName
required
Name of the file. string

Responses

HTTP Codes Description Schema
200 OK file

Errors

Delete File

Path

DELETE /sessions/{id}/files/{fileName}

Description

Delete a file from a session's working directory.

Method

DELETE

Parameters

Type Name Description Schema
path id
required
Id of the session. string
path fileName
required
Name of the file. string

Responses

HTTP Codes Description Schema
200 File is deleted N/A

Errors

Get Workspace Object Names

Path

GET /sessions/{id}/workspace

Description

Lists all object names of a specific session

Example Response "application/json"

[
    "model",
    "manualTransmission",
    "am.glm",
    "newdata"
]

Method

GET

Parameters

Type Name Description Schema
path id
required
Id of the session. string

Responses

HTTP Codes Description Schema
200 OK [ string ]

Errors

Create Workspace Object

Path

POST /sessions/{id}/workspace/{objectName}

Description

Upload a serialized R object into R session, The object has to be serialized using the 'serialize' R function. If an object with the same name already exists in the workspace, the object value will be overwritten. Simple R code to serialize an object:
R objectInR <- 10 serializedObjectInR <- serialize(objectInR, NULL) connection <- file('binaryFile','wb') POST('http://deployR.example/sessions/sessionId/workspace/objectName', body = connection)

Example Request

binary

Method

POST

Parameters

Type Name Description Schema
path id
required
Id of the session. string
path objectName
required
Name of the R object. string
body serializedObject
required
The binary file that contains serialized R object to be uploaded, the binary file Content-Type should be 'application/octet-stream' string

Responses

HTTP Codes Description Schema
200 OK N/A

Errors

Consumes

Get Workspace Object

Path

GET /sessions/{id}/workspace/{objectName}

Description

Returns an R object from a session as a .RData file stream

Example Response "application/octet-stream"

"[1] 5b 7b 22 63 72 65 61 74 69 6f 6e 54 69 6d 65 22 3a 22 32 30 31 36 2d 31 31 2d [27] 32 30 54 31 39 3a 35 30 3a 34 39 2e 37 35 32 37 36 37 36 22 2c 22 6e 61 6d 65"

Method

GET

Parameters

Type Name Description Schema
path id
required
Id of the session. string
path objectName
required
Name of the R object. string

Responses

HTTP Codes Description Schema
200 OK file

Errors

Delete Workspace Object

Path

DELETE /sessions/{id}/workspace/{objectName}

Description

Delete an object from a session.

Method

DELETE

Parameters

Type Name Description Schema
path id
required
Id of the session. string
path objectName
required
Name of the object. string

Responses

HTTP Codes Description Schema
200 OK N/A

Errors

Execute Code

Path

POST /sessions/{id}/execute

Description

Executes R code in the context of a specific session.

Example Request

{
    "code": "string",
    "inputParameters": [
        "array"
    ],
    "outputParameters": [
        "array"
    ]
}

Example Response "application/json"

{
    "success": true,
    "errorMessage": "",
    "outputParameters": [],
    "consoleOutput": "[1] 5\r\n",
    "changedFiles": []
}

Method

POST

Parameters

Type Name Description Schema
path id
required
Id of the session. string
body executeRequest
required
R code that needs to be executed ExecuteRequest

Responses

HTTP Codes Description Schema
200 OK ExecuteResponse

Errors

Create Snapshot

Path

POST /sessions/{id}/snapshot

Description

Create a snapshot from R session by saving the workspace and all files in the working directory into zip file, the return value will be the created snapshot Id.

Example Request

{
    "name": "string"
}

Example Response "application/json"

{
    "snapshotId": "8fac71e8-92a9-4959-a679-4376e5aab20d"
}

Method

POST

Parameters

Type Name Description Schema
path id
required
Id of the session. string
body createSnapshotRequest
required
Properties of the new snapshot. CreateSnapshotRequest

Responses

HTTP Codes Description Schema
201 Created CreateSnapshotResponse

Errors

Load Snapshot

Path

POST /sessions/{id}/loadsnapshot/{snapshotId}

Description

Loads a snapshot into R session by merging the workspace of the saved snapshot and target session. It will override the files in the working directory as well.

Method

POST

Parameters

Type Name Description Schema
path id
required
Id of the session. string
path snapshotId
required
Id of the saved snapshot. string

Responses

HTTP Codes Description Schema
200 OK N/A

Errors

Cancel Session

Path

POST /sessions/{id}/cancel

Description

Cancel a session by aborting the current execution operation, afterwards the session will be alive and ready to accept any calls. Cancel session is not guaranteed to interrupt the execution

Method

POST

Parameters

Type Name Description Schema
path id
required
Id of the session to cancel. string

Responses

HTTP Codes Description Schema
200 OK string

Errors

Snapshot APIs

These APIs provide different operations to access and manage workspace snapshots. A snapshot is a prepared environment image of a R session saved to Microsoft R Server, which includes the session's R packages, R objects and data files.

For optimal performance, consider the size of the snapshot carefully especially when publishing a service. Before creating a snapshot, ensure that you keep only those workspace objects you need and purge the rest. And, in the event that you only need a single object, consider passing that object alone itself instead of using a snapshot.

A snapshot can be loaded into any subsequent remote R session for the user who created it. For example, suppose you want to execute a script that needs three R packages, a reference data file, and a model object. Instead of loading these items each time you want to execute the script, create a snapshot of an R session containing them. Then, you can save time later by loading this snapshot using its ID to get the session contents exactly as they were at the time the snapshot was created.

Get Snapshots

Path

GET /snapshots

Description

List all the snapshots for the current user and display some info such as Id, display name, creation time, zip file size and owner for this snapshot.

Method

GET

Responses

HTTP Codes Description Schema
200 OK [ Snapshot ]

Errors

Get Snapshot

Path

GET /snapshots/{id}

Description

Get the snapshot content as zip file stream (zip file containing the working directory files and the workspace file)

Method

GET

Parameters

Type Name Description Schema
path id
required
Id of the snapshot. string

Responses

HTTP Codes Description Schema
200 OK file

Errors

Delete Snapshot

Path

DELETE /snapshots/{id}

Description

Delete a snapshot permanently and also it's content (zip file containing the working directory files and the workspace file)

Method

DELETE

Parameters

Type Name Description Schema
path id
required
Id of the snapshot. string

Responses

HTTP Codes Description Schema
200 OK string

Errors

Status APIs

You can retrieve the 'raw details' on the health of the system using the `GET /status` API call.

Get Status

Path

GET /status

Description

Gets the current health of the system.

Example Response "application/json"

{
    "statusCode": "green",
    "components": {
        "backends": {
            "statusCode": "green",
            "components": {
                "http://localhost:12805/": {
                    "statusCode": "green",
                    "components": null,
                    "details": {
                        "can Open Shell": true,
                        "can Write": true,
                        "can Read": true,
                        "can Zip": true,
                        "max Pool Size": 80,
                        "active Shell Count": 1,
                        "current Pool Size": 11
                    }
                }
            },
            "details": {}
        },
        "database": {
            "statusCode": "green",
            "components": null,
            "details": {
                "name": "main",
                "state": "Open"
            }
        },
        "ldap": {
            "statusCode": "green",
            "components": null,
            "details": {
                "host": "40.118.170.246",
                "port": 636,
                "version": 3
            }
        }
    },
    "details": {}
}

Method

GET

Responses

HTTP Codes Description Schema
200 OK StatusResponse

Errors

Schema Definitions

Session

PROPERTIES

id: string

name: string

owner: string

CreateSessionRequest

PROPERTIES

name: string

snapshotId: string

CreateSessionResponse

PROPERTIES

sessionId: string

Snapshot

PROPERTIES

id: string

name: string

owner: string

creationTime: string

contentSize: integer

CreateSnapshotRequest

PROPERTIES

name: string

CreateSnapshotResponse

PROPERTIES

snapshotId: string

ExecuteRequest

PROPERTIES

code: string

inputParameters: WorkspaceObject

outputParameters: string

ExecuteResponse

PROPERTIES

success: boolean

errorMessage: string

outputParameters: WorkspaceObject

consoleOutput: string

changedFiles: string

WorkspaceObject

PROPERTIES

name: string

value: object

ParameterDefinition

PROPERTIES

name: string

type: string

LoginRequest

PROPERTIES

username: string

password: string

RenewTokenRequest

PROPERTIES

refreshToken: string

AccessTokenResponse

PROPERTIES

token_type: string

access_token: string

expires_on: string

refresh_token: string

Error

PROPERTIES

message: string

link: string

PublishWebServiceRequest

PROPERTIES

snapshotId: string

code: string

description: string

operationId: string

inputParameterDefinitions: ParameterDefinition

outputParameterDefinitions: ParameterDefinition

WebService

PROPERTIES

name: string

version: string

creationTime: string

snapshotId: string

code: string

description: string

operationId: string

inputParameterDefinitions: ParameterDefinition

outputParameterDefinitions: ParameterDefinition

ConsoleOutputResponse

PROPERTIES

consoleOutput: string

StatusResponse

PROPERTIES

statusCode: string

details: object

components: StatusResponse

SwaggerJsonResponse

PROPERTIES

swaggerJson: string

Error Codes

APIs use the following generalized error codes:

Code Message Meaning
400 Bad Request The request was unacceptable, often due to missing a required parameter
401 Unauthorized No valid API key provided
402 Request Failed The parameters were valid but the request failed
403 Forbidden The server understood the request, but is refusing to fulfill it
404 Not Found The requested resource doesn't exist
409 Conflict The request conflicts with another request
410 Gone The request could not be completed due to a conflict with the current state of the resource
500 Internal Server Error Something went wrong on the server end. (These are rare)