Note that the token expires after 1 hour, and you must generate it again.
C# Example:
private async Task<string> GetS2SAccessTokenAsync()
{
using var client = new HttpClient();
using var content = new MultipartFormDataContent {
{ new StringContent("client_credentials"), "grant_type"},
{ new StringContent(_clientId), "client_id"},
{ new StringContent(_clientSecret), "client_secret"},
{ new StringContent(_scope), "scope"},
};
var responseMessage = await client.PostAsync(_tokenEndpoint, content);
var responseBody = await responseMessage.Content.ReadAsStringAsync();
if (!responseMessage.IsSuccessStatusCode)
throw new Exception($"Get Token failed ({responseMessage.StatusCode})");
var tokenData = JsonHelper.Deserialize<TokenResponse>(responseBody);
return tokenData!.Access_token;
}
The TokenData class
public class TokenResponse
{
public string Token_type { get; set; }
public int Expires_in { get; set; } = 0;
public int Ext_expires_in { get; set; }
public string Access_token { get; set; }
}
Calling S2S API Endpoints
The base URL for Cubu’s S2S API is https://s2s.api.app.cubu.com/<applicationId>/
The application ID is available on the registered application’s General tab.
You must provide the access token as a Bearer token in the Authorization header of each API request.
Example:
The following request returns the specified customer record: