Using the Mojo API

Using the Mojo API

There are three ways you can start to explore the Mojo API. To get started, login to your Mojo instance and select one of the following options on the dashboard:

An OpenAPI Specification is also available outside of a Mojo installation for reference and to build external tools against. You can browse and access the specifications.

API Endpoint

The Mojo API endpoint is the same URL that your Mojo instance Web UI is located at with the /api/ path added on to the end. For example, if you access your Mojo installation at https://7.7.7.7, your Mojo host is https://7.7.7.7 and the API endpoint will be https://7.7.7.7/api/. All API documentation uses ${MOJOHOST}/api/ as a placeholder for your specific API endpoint.

Login

To login to the Mojo API, you first need to obtain a JWT token. You do this by sending a POST request with your username and password to the /api/token/ endpoint. This token is then used in subsequent requests.

# HTTPie
TOKEN=$(http --verify no POST ${MOJOHOST}/api/token/ username=${MOJOUSER} password=${MOJOPASS}  | jq -r '.access')
# curl
TOKEN=$(curl -s -L -k -H "Content-Type: application/json" -d '{"username": "${MOJOUSER}", "password": "${MOJOPASS}"}' "${MOJOHOST}/api/token/" | jq -r '.access')

Now that you have obtained a token, it is good for 24 hours. It should be inserted into the Authorization header of any subsequent API requests. To test your token, send a GET request to /api/users/me/

# HTTPie
http --verify no ${MOJOHOST}/api/users/me/ Authorization:"Bearer ${TOKEN}"
# curl
curl -s -L -k -H "Content-Type: application/json" -H "Authorization: Bearer ${TOKEN}" "${MOJOHOST}/api/users/me/"