Platform Docs

Querying Web Services

To see our APIs in action, visit the Clover Android SDK examples directory in the Clover Android SDK. The examples use the Clover APIs to connect to Services, query Clover ContentProviders, and fetch data directly from the Clover REST API.

Querying a Web Service

WebServiceActivity shows how the Clover REST API can be queried directly once the Clover Account and authToken are retrieved.

  1. Get a merchant's CloverAccount:
private Account mAccount;
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  mAccount = CloverAccount.getAccount(this);
  1. Get your app's authToken using the CloverAuth.authenticate call in a background thread:
CloverAuth.AuthResult authResult = CloverAuth.authenticate(WebServiceActivity.this, mAccount);
  1. If successful, the AuthResult will contain the authToken and baseUrl. Query the REST API to get merchant information using the included CustomHttpClient:
CustomHttpClient httpClient = CustomHttpClient.getHttpClient();

// First we get the base URL, merchant ID, and API token
String baseUrl = authResult.authData.getString(CloverAccount.KEY_BASE_URL);
String merchantId = authResult.merchantId;
final String apiToken = authResult.authToken;

// Now we get merchant information using the merchant ID
String merchantUri = "/v3/merchants/" + merchantId;
url = authResult.baseUrl + merchantUri + "?access_token=" + authResult.authToken;
result = httpClient.get(url);

You can find more examples in Clover's Android Examples Repository on GitHub.