Set up Basic authentication
Use Basic authentication when the API you monitor expects a username and password. You create a Basic Auth setting for the API's domain, store the credentials in a token, and select that setting and token on each monitor that needs them. APIContext then sends an Authorization: Basic header on every request the monitor makes, built from the username and password in the token.
Prerequisites
- The EDITOR role or higher in the project. The Monitor Authentication menu item only appears for editors. See Access Roles.
- The domain of the API, for example
api.example.com, and the username and password it accepts. - A monitor that calls that API, or the intention to create one. See how to add a monitor.
Steps
-
Open Monitor Authentication from Configure Monitoring in the left menu, then click Add new Auth Setting.
-
In the Create Authentication panel, fill in the fields:
- Name: a label of at least 3 characters, for example
Example API Basic. - Endpoint Domain: the plain domain name with no slashes, for example
api.example.com. - Authentication Type: select Basic Auth.
The other fields on the panel are informational or apply to other types. Basic Auth has no Client ID, Client Secret, or URL fields. You cannot change the type after you save the setting.
- Name: a label of at least 3 characters, for example
-
Click Save. APIContext opens the new setting's page, which shows an empty tokens table.
-
Click Add New Token. In the Add New Token panel, fill in the fields:
- Name: a label of at least 3 characters, for example
Example API production user. - Username: the username the API expects.
- Password: the password for that username. The field is masked.
Domain is read-only and is filled in from the setting.
- Name: a label of at least 3 characters, for example
-
Click Save. The token appears in the tokens table.
-
Open the monitor that calls the API, expand its Authentication section, and choose the setting you created in the list that shows Select an Auth Setting. Then choose your token in the list that shows Select a Token.
-
Save the monitor.
Result
The monitor sends the credentials on every request. After its next run, the result shows your API's response. A 401 status code means the API rejected the credentials: open the setting's page, click the token's row, correct the Username or Password, and click Save. Monitors that use the token pick up the change without further edits.
A Basic Auth token has no expiry, so its Expires column shows Never. Update the token whenever the password changes at the API. For tokens that do expire, see Troubleshoot expired authentication tokens.
The Use Basic Auth for Get Token API switch on an OAuth 2 setting is a different feature. It controls how APIContext calls the provider's token endpoint, and it does not add Basic authentication to your monitors.
Next steps
- Monitor Authentication: every authentication type and how settings and tokens fit together.
- Authentication Model: why APIContext separates settings from tokens.
- Troubleshoot expired authentication tokens: restore monitoring when a credential lapses.