Authentication

Authentication

Welcome to the Safsira API Authentication documentation. In this guide, we will explore how to use OAuth 2.0 Bearer Token to secure access to our APIs. OAuth 2.0 is a widely adopted industry standard for user authentication and authorization, providing a secure and flexible way to grant access to resources on behalf of a user. Bearer Token is one of the most common token types used in OAuth 2.0 for securing API endpoints.

ℹ️

This guide assumes you have some understanding of OAuth 2.0 flow. Please refer to these resources for additional information:

Getting an access token

To learn more about account setup and getting an access token, please refer to this guide: Developer Apps

Making Requests

Once you have an access token, you can make authorized requests to Safsira's API. Simply include the token in the Authorization header of your requests:

Authorization: Bearer <access_token>

In addition, you must use the application/json content type for your requests:

Content-Type: application/json

Getting your Account ID

You can use the Safsira API to perform various actions, including requesting products, adding recipients, placing orders, and shipping orders. Refer to the API Reference (opens in a new tab) for detailed information on all available endpoints and how to use them.

You must use a custom header to specify the account you are making requests on behalf of. This is done by including the SC-Account-Id header in your requests:

SC-Account-Id: <account_id>

To get your current account account_id you can make a GET request to the following endpoint:

https://api.safsira.com/v1/users/me

Response:

{
    "id": "<your_user_id>",
    "username": "<your_username>",
    "first_name": "<your_name>",
    "last_name": "<your_last_name>",
    "email": "<your_email>",
    "phone": "<your_phone_number>",
    "current_account": {
        "id": 208,
        "name": "<your_account_name>",
        "default_billing_address": {
            ...
        },
        ....
    },
    ...
}

From that response, you can get your account_id (the id key) from the current_account object.

If you have access to multiple accounts, you can make a GET request to the following endpoint to get a list of accounts you have access to:

https://api.safsira.com/v1/accounts/

Response:

{
    "count": 2,
    "next": null,
    "previous": null,
    "results": [
        {
            "id": 208,
            "name": "<your_account_name>",
            "default_billing_address": {
                ...
            },
            ....
        },
        {
            "id": 209,
            "name": "<your_account_name>",
            "default_billing_address": {
                ...
            },
            ....
        }
    ]
}