how to append int value to GET url of retrofit in android

8.8k Views Asked by At

I have following url http://54.169.227.89:90/DataAccessService.svc/GetProducts/2 which i wanted to use i retrofit get method How to append 2 which is company id which i get from sharepreference during login

Here is ma interface code

public interface ProductsGet {


    String Company_id = OrderApplication.CompanyID_New;


    @GET("/DataAccessService.svc/GetProducts/")
    public void getProducts( Callback<List<ProductsNew>> response);
}
2

There are 2 best solutions below

4
Godfather On BEST ANSWER

In order to make end point dynamic either you can implementing Endpoint and make use of setUrl() or you can use URL manipulation block which is surrounded by { and }.

     int Company_id = OrderApplication.CompanyID_New;
        
         public interface ProductsGet {
    @GET("/DataAccessService.svc/GetProducts/{COMPANY_ID}") 
public void getProducts(@Path("COMPANY_ID") String Company_id, Callback<List<ProductsNew>> response);
            
            yourreference.getProducts(company_id,new Callback...)
2
Keshav Gera On
Call<IndentsPojo> call1 = apiInterface.getReport("Basic YWRtaW46MTIzNA==", 1, 10,
                "",
                "", "", "",
                "01-Jan-2018", "06-Mar-2019");

   @GET("Indent/IndentVsIssueReport?")// TODO GET CALL HERE
    Call<IndentsPojo> getReports(@Header("Authorization") String token,
                                     @Query("pageNumber") int pageNumber,
                                     @Query("pageSize") int pageSize,
                                     @Query("quickSearch") String quickSearch,
                                     @Query("indentNo") String indentNo,
                                     @Query("distilleryid") String distilleryid,
                                     @Query("brandcategoryid") String brandcategoryid,
                                     @Query("IssueFromDate") String fromDate,
                                     @Query("IssueToDate") String toDate
                                    );

enter image description here