Auth
Sign your customers up and log them in on your own website, with an email and a password. Your server makes these calls with your API key and gets the customer's session back. The customer joins your store as if they had signed up in your salon, and shows in your Bench like any other customer. The API comes with the Retail plan.
Register
Creates the customer's account and signs them in.
https://api.diamra.com/v1/auth/registercurl https://api.diamra.com/v1/auth/register \
-H "Authorization: Bearer $DIAMRA_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "email": "jane@example.com", "password": "their-password", "name": "Jane Doe" }'HTTP/2 201
content-type: application/json
request-id: req_3b1f9a07c2e84d55
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "bearer",
"expires_in": 3600,
"expires_at": 1762207200,
"refresh_token": "kq3xv7j2lm4p",
"customer": {
"id": "6f1c2a9e-4b7d-4e2a-9c3f-8d5e1b2a7c40",
"email": "jane@example.com",
"name": "Jane Doe",
"access": "granted"
}
}An email that already has an account answers 409 email_exists, even when the customer never signed up on your website. Log them in instead.
Log in
Signs in a customer who has a password. The answer is the same session as Register's, with a 200.
https://api.diamra.com/v1/auth/logincurl https://api.diamra.com/v1/auth/login \
-H "Authorization: Bearer $DIAMRA_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "email": "jane@example.com", "password": "their-password" }'A wrong password and an email without an account both answer 400 invalid_credentials, so nobody can use this call to learn which emails have accounts. Customers who signed up in your salon with Google or a phone number have no password until they set one with Reset a password.
Refresh
An access token lasts an hour. Before it runs out, trade the refresh token for a new session. Each refresh token works once: keep the new one from every answer. A used one answers 400 refresh_token_invalid, and the customer has to log in again.
https://api.diamra.com/v1/auth/refreshcurl https://api.diamra.com/v1/auth/refresh \
-H "Authorization: Bearer $DIAMRA_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "refresh_token": "kq3xv7j2lm4p" }'Log out
Ends the session the refresh token belongs to. The customer stays signed in anywhere else, such as your salon or another device. The refresh token stops working at once. The access token runs out on its own within the hour, so drop it as well.
https://api.diamra.com/v1/auth/logoutcurl https://api.diamra.com/v1/auth/logout \
-H "Authorization: Bearer $DIAMRA_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "refresh_token": "kq3xv7j2lm4p" }'The answer is { "logged_out": true } with a 200, also for a refresh token that no longer works: that session is over already.
Reset a password
Two calls. The first emails the customer an 8-digit code, signed with your store's name. The second takes the code and the new password, and answers the session, as Log in does. Customers who signed up with Google can set a first password this way, since their account has an email address.
https://api.diamra.com/v1/auth/reset-passwordcurl https://api.diamra.com/v1/auth/reset-password \
-H "Authorization: Bearer $DIAMRA_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "email": "jane@example.com" }'The answer is a 202 with an empty object, whether or not the email has an account, so nobody can use this call to learn which emails have one. A code lasts an hour. Diamra sends at most one email a minute to an address, so asking again sooner leaves the first code working.
https://api.diamra.com/v1/auth/reset-password/confirmcurl https://api.diamra.com/v1/auth/reset-password/confirm \
-H "Authorization: Bearer $DIAMRA_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "email": "jane@example.com", "code": "48201937", "password": "their-new-password" }'A code works once. A wrong or used code answers 400 code_invalid. A password that is too short answers 400 password_too_weak, and the customer then needs a new code.
The session
Register, log in, refresh and the reset's second call all answer it.
Limits
Over a limit the answer is 429 rate_limit with a Retry-After header in seconds. Wait that long, then try again.
Errors
HTTP/2 409
content-type: application/json
request-id: req_9d24c1e07b3a4f68
{
"error": {
"type": "invalid_request_error",
"code": "email_exists",
"message": "An account with this email already exists. Log the customer in instead.",
"param": "email"
}
}