Our API powers everything in the app— our UI makes calls to the backend, which operates the app. You can learn more about how these work and make your own calls in this section.
Obtain API Key
Initialize Session
REQUIRE_USER_AUTHENTICATION=1
, you'll need to create a new session before you can make any API calls. If your project does not require user auth, you can skip straight to making API calls with your API key.To initialize a session, see the POST /api/sessions
endpoint. You'll need to supply your email and password as a JSON payload. Here's an example of how to do this in Python.Before starting, first nano ~/YOUR_SECRETS_PATH/.env.mage
, replacing YOUR_SECRETS_PATH
with an apporpriate directory, to create a new secrets file. Then add the following to your secrets file:Authenticate Session
oauth_token
cookie. This can be done simply in Python requests with the following, where token
is the value of the token
key in the response payload:Make API calls
api_key
or in the request payload body as api_key
. You can find your API key quickly by navigating to the GUI and checking the request log from the container or going to the “Network” tab in your browser’s developer tools.
REQUIRE_USER_AUTHENTICATION
is enabled for your project— that is, when users must login to access Mage.
The token provided in the session payload is the raw value. There are two ways to authenticate with this token:
200
status in the main payload. The any error code will be stored in the error
key. For example, the following is a response from a failed session auth:
mage-ai/mage_ai/api
directory here.
mage_ai/tests/api/operations/test_[resource_name].py
;
replace resource_name
with the name of your resource.
Paste in the following sample code into your file:
UserResource
.
You’ll need to update the test logic to unit test your custom API endpoint.