Search code examples
androidlistretrofit

How to send list of integers as query in Get Retrofit request android


Here's what I'm doing in my request :

@GET("home/products")
suspend fun getSaleProducts(
    @Query("store_id") storeId: Int? = null,
    @Query("category_id") categories : List<Int>?) 

and the query looks like this in the request : category_id=26&category_id=33&category_id=40 And I want it to look like this: category_id=26,33,40


Solution

  • I changed the List type to String by using joinToString() method on the list of Ids. and it works fine

    @Query("category_id") categories : List? to

    @Query("category_id", encoded = true) categories: String
    should use encoded = true to get work.