Getting Started with Otto API

This page will help you get started with Otto API

This guide will provide a walk through of authenticating with the Authentication API and listing all users with the OData API.

Authenticating with Username and Password

To authenticate with the API you will need to provide: organizationId, username, and password. The authentication endpoint is https://api.ottolearn.io/authenticate/login

const credentials = {
    "organizationId": 1,
    "username": "[email protected]",
    "password": "secret"
};

fetch(
  'https://api.ottolearn.io/authenticate/login',
  {
    method: 'POST',
    body: JSON.stringify(credentials),
    headers:{
      'Content-Type': 'application/json'
    }
  }
)
    .then((response) => {
      switch (response.status) {
        case 403:
          throw new Error(`
            Access Denied.
            Invalid credentials provided or user is not active.
          `);
        case 200:
          // Credentials were authenicated successfully. Parse JSON response.
          return response.json();
        default:
          throw new Error(`
          	Unexpected response from API.
          	Please try again later
          `);
      }
    })
    .then((body) => {
      /**
       * SAMPLE BODY
       *  {
       *     "userId": 9,
       *     "organizationId": 1,
       *     "sessionToken": "123456789abcdefgh"
       *  }
       */
       console.log('BODY', body);
       const sessionToken = body.sessionToken;
  
       return sessionToken;
    });

List all Users

To list all users we will need to send the API request to the endpoint https://api.ottolearn.io/v1/rest/user. We will also need to set the Authorization header when sending requests to the OData API.

const sessionToken = '123456789abcdefgh';

fetch(
  'https://api.ottolearn.io/v1/rest/user',
  {
    method: 'GET',
    headers:{
      'Authorization': sessionToken
    }
  }
)
    .then((response) => {
      switch (response.status) {
        case 403:
          throw new Error(`
            Access Denied.
            Invalid session token
          `);
        case 200:
          // Query was completed successfully
          return response.json();
        default:
          throw new Error(`
						Unexpected response from API.
						Please try again later
					`);
      }
		})
    .then((body) => {
      /**
       * SAMPLE BODY
       * [
       *    {
       *        "id": 1,
       *        "attribute": {
       *            "emailAddress": "[email protected]",
       *            "firstName": "Bob",
       *            "lastName": "Maximillian",
       *            "owner": true,
       *            "phoneNumber": null
       *        },
       *        "admin": false,
       *        "status": "inactive",
       *        "createdAt": "2017-08-28T20:32:19.000Z",
       *        "updatedAt": "2017-11-21T17:17:42.000Z",
       *        "organizationId": 1,
       *        "engagementSchedule": 1,
       *        "timezone": 218,
       *        "allowNotifications": false
       *    },
       *    {
       *        "id": 2,
       *        "attribute": {
       *            "emailAddress": "[email protected]",
       *            "firstName": "Boehm",
       *            "lastName": "Delmer",
       *            "owner": true,
       *            "phoneNumber": null
       *        },
       *        "admin": false,
       *        "status": "inactive",
       *        "createdAt": "2017-08-28T20:32:19.000Z",
       *        "updatedAt": "2017-11-16T20:08:59.000Z",
       *        "organizationId": 1,
       *        "engagementSchedule": 1,
       *        "timezone": 218,
       *        "allowNotifications": false
       *    },
       *        …
       * ]
       */
       console.log('BODY', body);
    });