Xeppo API Login

Knowledge base

To log in to Xeppo's API, users should POST their credentials as follows:

{
  "username": "string",
  "password": "string"
}

C# Example:

protected virtual async Task<bool> AuthorizeAsync()
{
    if (_accessToken == null || _accessToken.expiry > DateTime.UtcNow)
    {
        string username = IsServiceAccount ? $"{_apiUsername}@xepposervice.com.au" : _apiUsername;
        using var content = new StringContent(JsonConvert.SerializeObject(new { username = username, password = _apiPassword }), Encoding.UTF8, "application/json");
        using var response = await _client.PostAsync($"auth/v1/login", content);
        if (!response.IsSuccessStatusCode)
        {
            Console.WriteLine($"Error received during auth: {response.StatusCode}");
            return false;
        }

        _accessToken = JsonConvert.DeserializeObject<AccessToken>(await response.Content.ReadAsStringAsync());
        if (_accessToken == null)
        {
            Console.WriteLine($"No token received from auth");
            return false;
        }

        _accessToken.expiry = DateTime.UtcNow.AddSeconds(_accessToken.expires_in - 5); //5 seconds of grace
    }

    _client.DefaultRequestHeaders.Authorization =
        new AuthenticationHeaderValue(_accessToken.token_type, _accessToken.access_token);

    return true;
}

Logging in via the GET login endpoint will be deprecated after 30/06/23.

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.