# Authorization

A predicate for using the Live Services API is to obtain authorisation credentials. The Authorization API calls are provided to help you achieve this goal. Ther are two main approaches to autorize against API:

Authorization token

You will need a valid username and password credentials created for your organisation . The user authentication credentials should be passed in JSON format like so:

{
 "password": "<admin_password>",
 "email": "<admin@organization_name.com>"
}

API Token authorization example:

[Request] POST https://<base_api_url>/auth/authorize 
{
  "password":"<admin_password>",
  "email":"admin@<your_organization_name>.tv"
}
[Request Headers] {"Content-Type":"application/json","Accept":"application/json"}
[Page] https://<base_api_url>/authorize
[Response] 200
[Request Cookies] []

[Response Headers] {"Content-Type":["application/json"],"Content-Length":["3972"],"Connection":["keep-alive"],....}
[Response] 
{
 "status":true,
 "data":
   {
     "AccessToken":"<access_token>",
     "ExpiresIn": 3600,
     "TokenType": "Bearer",
     "RefreshToken":"<refresh_token>",
     "IdToken":"<valid_id_token>"
   }
}

You need to keep the "IdToken" in a variable for all subsequent API calls. You will need to place it in the [request headers] as a header of type "Authorization": and the value of "IdToken".

[Request Headers] {"Content-Type":"application/json","Accept":"application/json","Authorization":"<IdToken>"}

API KEY

To get api key you will need autorization token as a pre-requisite taken by procedure above.

Steps:

  1. Get authorization token.
  2. Store new token giving a name to it (autorize with idToken in Request Headers).
  3. Get Api key by guid (autorize with idToken in Request Headers).
  4. Store received Api Key guid on a save place.
  5. Use it for API calls which have 'private' word inside API endpoint.

API Key example:

  1. Store new token giving a name to it.
[Request] POST https://<base_api_url>/broker/api-keys
[Request Headers] {"Content-Type":"application/json","Accept":"application/json","Authorization":"<IdToken>"}
[Page] https://<base_api_url>/authorize
[Response] 201

[Response Headers] {"Content-Type":["application/json"],"Content-Length":["3972"],"Connection":["keep-alive"],....}
[Response] 
{
  "status": true,
  "data": "Item was created successfully",
  "url": "<base_api_url>/broker/api-keys/<api_key_guid>"
}
  1. List single API key
[Request] GET https://<base_api_url>/broker/api-keys/<api_key_guid>
{
  "name": "test_automation2",
  "active": true
}
[Request Headers] {"Content-Type":"application/json","Accept":"application/json","Authorization":"<IdToken>"}
[Page] https://<base_api_url>/authorize
[Response] 200

[Response Headers] {"Content-Type":["application/json"],"Content-Length":["3972"],"Connection":["keep-alive"],....}
[Response] 
{
  "status": true,
  "data": {
    "name": "test_automation2",
    "guid": "<api_key_guid>",
    "active": 1,
    "value": "<api_key>" //This is the value of the api key. Store it to a save place
  }
}