bluedata-3.7bluedata

How to work with sessions with the BlueData REST API?


I would like to use the BlueData API to programmatically manage by BlueData installation.

I have seen some documentation here - it appears that I need to start off with Fetching a session but I would expect to create a session before I can fetch it.

How do I create a session and use that in subsequent operations?


Solution

  • Introduction

    The API docs listed in the question don't show the API call for creating a session. Instructions for creating a session can, however, be found here, but I'm also adding the details in this answer in case the link goes away.

    Note that you can browse the full BlueData API docs if you have a running BlueData installation:

    http://<controller-ip>/apidocs/
    

    Anyway, the steps to create a session and use the session in a subsequent call such as Retrieve all tenants are listed below:

    Create Session

    Write the login.json file:

    cat <<EOF> ./login.json
    {
         "name": "admin",
         "password": "admin123"
    }
    EOF
    

    Set the controller IP:

    # Set this to your controller IP address
    
    CONTROLLER_IP=10.0.0.1 
    

    You can then submit a login request:

    curl -i -X POST -d@login.json http://${CONTROLLER_IP}:8080/api/v1/login
    

    Returns

    HTTP/1.1 201 Created
    Server: BlueData EPIC 3.7
    Location: /api/v1/session/df1bfacb-xxxx-xxxx-xxxx-c8f57d8f3c71
    Date: Mon, 15 Jul 2019 16:47:54 GMT
    Content-Type: text/plain
    Content-Length: 13
    Access-Control-Allow-Origin: *
    
    201 Created
    

    Set the SESSION ID:

    SESSION_ID=/api/v1/session/df1bfacb-xxxx-xxxx-xxxx-c8f57d8f3c71

    Use Session to get a list of Tenants

    Use the SESSION ID in a subsequent call, e.g.

    curl -X GET -H "X-BDS-SESSION:${SESSION_ID}" http://${CONTROLLER_IP}:8080/api/v1/tenant
    

    This example for me returns:

    {"_links":{"self":{"href":"/api/v1/tenant"}},...
    

    See also: