I am paring CollectionListing
Api from Shopify and I need to pass 'collecton_listing_id'
as parameter in url
. I am passing the id but unable to get response in Callback.
Note: I have tested the api with parameters in Postman and works fine.
Here is my implementation.
ProductActivity.java
private void processProductIds() {
apiInterface = APIClient.getClient().create(ApiInterface.class);
Call<List<Integer>> call = apiInterface.getProductIds(key, id);
call.enqueue(new Callback<List<Integer>>() {
@Override
public void onResponse(Call<List<Integer>> call, Response<List<Integer>> response) {
String s = String.valueOf(response.body());
Log.d("S", "onResponse:" + s);
}
@Override
public void onFailure(Call<List<Integer>> call, Throwable t) {
}
});
}
ApiInterface.java
public interface ApiInterface {
@GET("collection_listings/{collection_listing_id}/product_ids.json")
Call<List<Integer>> getProductIds(@Header("Authorization") String accessToken, @Path("collection_listing_id") long id);
}
Model Class
public class IdExample {
@SerializedName("product_ids")
@Expose
private List<Integer> productIds = null;
public List<Integer> getProductIds() {
return productIds;
}
public void setProductIds(List<Integer> productIds) {
this.productIds = productIds;
}
}
JSON Response
{
"product_ids": [
1331092619350,
1331125551190,
1331126599766,
1331121651798
]
}
Thank you.
3
Answers
You need to change the return type of
getProductIds
fromCall<List<Integer>>
toCall<IdExample>
EDIT: (as discussed in the comments)
You should also change
List<Integer> productIds
toList<Long> productIds
Try to call API using,
It should be like this
Then change api interface like this