Query web services

United States

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 account;
protected void onCreate(Bundle savedInstanceState) {
  account = CloverAccount.getAccount(this);
  1. Get your app's authToken using the CloverAuth.authenticate call in a background thread:
private void getCloverAuth() {
  new AsyncTask<Void, Void, CloverAuth.AuthResult>() {
    protected CloverAuth.AuthResult doInBackground(Void... params) {
      try {
        Context context = getApplicationContext();
        return CloverAuth.authenticate(context);
      } catch (Exception e) {
        Log.e(TAG, "Error authenticating", e);
      return null;

    protected void onPostExecute(CloverAuth.AuthResult result) {
      cloverAuth = result;
      if (cloverAuth != null && cloverAuth.authToken !=null) {
        mToken.setText("Token: " + cloverAuth.authToken);
      } else {
        mToken.setText("Error retrieving token."));

A successful authentication attempt returns an authResult containining the authToken and baseUrl.

  1. Query the REST API to get merchant information using an HTTP client of your choice.
// First, get the merchant ID and base URL
// and use them to construct the request URL
String merchantId = cloverAuth.merchantId;
String merchantUri = "/v3/merchants/" + merchantId;
String url = cloverAuth.baseUrl + merchantUri;

OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
  .addHeader("Authorization", "Bearer " + cloverAuth.authToken)

// Second, get merchant information using the request URL
try {
  Response response = client.newCall(request).execute();
  if (!response.isSuccessful()) throw new IOException(String.valueOf(response));
} catch (IOException e) {

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



There are important changes to the Android SDK auth token generation.