The Auth API provides an NPM package to help you get started quickly.
access key
and account id
, you can grab these from TheAuthAPI dashboard.
For further instructions on creating an account, check out our how to guides.
[object instance].[endpoint].[method]
For example, getting the projects for an account would be: theAuthApiClient.projects.getProjects("ACCOUNT_ID")
,
Similarly, getting the api keys would be:
theAuthApiClient.apiKeys.getKeys("PROJECT_ID")
endpoint | attribute | example |
---|---|---|
/api-keys | apiKeys | client.apiKeys.createKey("MY_KEY") |
/projects | projects | client.projects.createProject("MY_PROJECT") |
/accounts | accounts | client.accounts.createAccount("MY_ACCOUNT") |
HTTP Method | method name | example |
---|---|---|
POST | create* | client.apiKeys.createKey({ name: "KEY_NAME", projectId: "PROJECT_ID" }) |
GET | get* | client.apiKeys.getKeys() |
DELETE | delete* | client.apiKeys.deleteKey("MY_KEY") |
PATCH | update* | client.apiKeys.updateKey("MY_KEY", { name: "UPDATED_KEY_NAME" }) |
apiKeys.isValidKey
which returns true
if the key is valid, false
otherwise.
isValidKey
throws an ApiRequestError
if thereโs a network issue, itโs advised to wrap it in a try/catch
to handle the potential error
apiKeys.authenticateKey
which returns an ApiKey.
getKeys
projectId
where the keys are not active
projectId
when listing the API keys:
getKeys({ projectId: "PROJECT_ID" })
, otherwise if your access key is created at project level, you donโt have to specify projectId
,
the access keyโs projectId
will be used to get the API-keys (i.e. youโll see only the keys of the project your access key is created against)
rotateKey
method. This method while clone your key and return you with a new one.
2xx
range. ApiRequestError
provides two properties to distinguish the type of the error
statusCode
HTTP status codemessage
the message the server responded with in the bodyapiKeys.getKey("invalid-key")
, the server responds with a 404 error and an ApiResponseError
is thrown
statusCode
, โInvalid client Keyโ is the message
, you can access these properties using error.statusCode
and error.message
respectively