Analytics Library REST API

      +

      Overview

      The Analytics Library REST API is provided by the Analytics service. This API enables you to manage the libraries that are used to create N1QL for Analytics user-defined functions.

      The API schemes and host URLs are as follows:

      • http://localhost:8095/

      • https://localhost:18095/ (for secure access)

      Note that this API is only available on the loopback interface of a node running the Analytics service.

      Version information

      Version : 0.1

      Consumes

      • multipart/form-data

      Produces

      • application/json

      Paths

      This section describes the operations available with this REST API.

      Read All Libraries

      GET /analytics/library/

      Description

      Returns all libraries and functions.

      Responses

      HTTP Code Description Schema

      200

      Success. Returns an array of objects, each of which contains information about a single library.

      < Libraries > array

      404

      Not found. The path may be missing its trailing slash.

      No Content

      500

      Internal server error. Incorrect path or port number, incorrect credentials, badly formatted parameters, or missing arguments.

      Errors

      Security

      Type Name

      basic

      Analytics Admin

      Example HTTP request

      The example below fetches all defined libraries.

      Curl request

      curl -X GET \
      http://localhost:8095/analytics/library/ \
      -u Administrator:password

      Example HTTP response

      Response 200

      [ {
        "scope" : "travel-sample/inventory",
        "hash_md5" : "b0e764a12aa922de80b14bab9a7d2fb3",
        "name" : "mylib"
      } ]

      Create or Update a Library

      POST /analytics/library/{scope}/{library}

      Description

      Creates the specified library and its associated functions. If the specified library exists, the existing library is overwritten.

      • To add a function to a library, update the library with all existing functions, plus the new function.

      • To update a function, update the library with all existing functions, including the updated function definition.

      • To delete a function from a library, update the library with all existing functions, without the deleted function.

      Parameters

      Type Name Description Schema

      Path

      library
      required

      The name of a library.

      string

      Path

      scope
      required

      The name of the Analytics scope containing the library.

      The scope name may contain one or two identifiers, separated by a slash (/). You must URL-encode this parameter to escape any special characters.

      string

      FormData

      data
      required

      The library and all its dependencies, packaged by shiv.

      file

      FormData

      type
      required

      The language of the library.

      enum (python)

      Responses

      HTTP Code Description Schema

      200

      The operation was successful.

      object

      400

      Bad request. A parameter has an incorrect value.

      Errors

      500

      Internal server error. Incorrect path or port number, incorrect credentials, badly formatted parameters, or missing arguments.

      Errors

      Security

      Type Name

      basic

      Full Admin

      Example HTTP request

      The example below creates or updates a library called mylib in the travel-sample.inventory scope. The Python code is stored in a file called lib.pyz.

      Curl request

      curl -X POST \
      http://localhost:8095/analytics/library/travel-sample%2Finventory/mylib \
      -u Administrator:password \
      -d type=python
      -d data=lib.pyz
      The dot separator within the scope name is converted to a slash (/), which is then URL-encoded as %2F.

      Delete a Library

      DELETE /analytics/library/{scope}/{library}

      Description

      Deletes the specified library entirely.

      Parameters

      Type Name Description Schema

      Path

      library
      required

      The name of a library.

      string

      Path

      scope
      required

      The name of the Analytics scope containing the library.

      The scope name may contain one or two identifiers, separated by a slash (/). You must URL-encode this parameter to escape any special characters.

      string

      Responses

      HTTP Code Description Schema

      200

      The operation was successful.

      object

      404

      Not found. The library name in the path may be incorrect.

      string

      500

      Internal server error. Incorrect path or port number, incorrect credentials, badly formatted parameters, or missing arguments.

      Errors

      Security

      Type Name

      basic

      Full Admin

      Example HTTP request

      The example below deletes the mylib library from the travel-sample.inventory scope.

      Curl request

      curl -X DELETE \
      http://localhost:8095/analytics/library/travel-sample%2Finventory/mylib \
      -u Administrator:password
      The dot separator within the scope name is converted to a slash (/), which is then URL-encoded as %2F.

      Definitions

      This section describes the properties returned by this REST API.

      Libraries

      Name Description Schema

      scope
      optional

      The name of the Analytics scope containing the library.

      The scope name may contain one or two identifiers, separated by a slash (/).
      Example : "travel-sample/inventory"

      string

      hash_md5
      optional

      A MD5 hash of the library residing on the server.

      string

      name
      optional

      The name of the library.
      Example : "mylib"

      string

      Errors

      Name Description Schema

      error
      required

      An error message.

      string

      Security

      The Analytics Library REST API supports HTTP basic authentication. Credentials can be passed via HTTP headers.

      Full Admin

      To Create or Update a Library or Delete a Library, users must have the Full Admin RBAC role.

      Type : basic

      Analytics Admin

      To Read All Libraries, users must have one of the following RBAC roles:

      • Full Admin

      • Cluster Admin

      • Analytics Admin

      Type : basic

      Refer to Roles for more details.