Skip to main content

Apito REST API Integration with Android

Use any lib of you choice we are choosing the most popular lib called Retrofit for this example. To add bearer token in retrofit, you have to create a class that implements Interceptor

Using Retrofit


Always remember to replace API_SECRET of the Bearer Token and project-id of the URL with the correct value from apito console. Go to this page if you do not know where to find your api secrets and endpoints for your project

public class TokenInterceptor implements Interceptor{

public Response intercept(Chain chain) throws IOException {

//rewrite the request to add bearer token
Request newRequest=chain.request().newBuilder()
.header("Authorization","Bearer <API_SECRET>")

return chain.proceed(newRequest);

Now add your Interceptor class in OKHttpClient object and add that obejct in Retrofit object:

TokenInterceptor interceptor = new TokenInterceptor();

OkHttpClient client = new OkHttpClient.Builder()

Retrofit retrofit = new Retrofit.Builder()