Login

Last modified on March 27, 2024

The first API call in your code needs to be Login. To log in, send a POST request to /login with a body containing AlertSite login and password in the JSON format (see the syntax below). A successful login returns a session ID. You need this ID to generate the authentication token for subsequent API calls, as explained in Authentication.

Usually a login is only required once at the beginning of your code.

There is no explicit logout operation. A session ID automatically expires 15 minutes after its last use. You can request a new session ID by logging in again.

Syntax

Request URL

POST https://www.alertsite.com/alertsite-restapi/login

Request Body

{
  "login": "[email protected]",
  "password": "passw0rd"
}

Response Body

Successful response contains status 0 and the session value for authenticating subsequent API calls:

{
  "metadata": {
    "login": "[email protected]",
    "session": "ef770427109e343e",
    "status": "0",
    "message": "No errors."
  }
}

Error response contains a non-zero status:

{
  "metadata": {
    "login": "[email protected]",
    "status": "40",
    "message": "Invalid login information."
  }
}

Code Examples

cURL

Windows

curl -X POST https://www.alertsite.com/alertsite-restapi/login
  -H "Content-Type: application/json"
  -d "{\"login\": \"[email protected]\", \"password\": \"passw0rd\"}"

Note: New lines are added for readability. The actual command should be one continuous line.
*nix, OS X

curl -X POST https://www.alertsite.com/alertsite-restapi/login \
  -H "Content-Type: application/json" \
  -d '{"login": "[email protected]", "password": "passw0rd"}'

Python

This code logs into AlertSite and prints the session ID.

Python

import requests # Requests library – http://docs.python-requests.org
import json

baseUrl = 'https://www.alertsite.com/alertsite-restapi'
login = '[email protected]' # Replace with your AlertSite login email
password = 'pa55w0rd' # Replace with your AlertSite password

payload = {'login': login, 'password': password}
r = requests.post(baseUrl + '/login', data=json.dumps(payload), headers={'Content-Type': 'application/json'})
result = r.json()['metadata']
if int(result['status']) == 0:
    print('Session ID: ' + result['session'])
else:
    print('Error {status}: {message}'.format(**result))

See Also

AlertSite JSON API

Highlight search results