Carlo Matulessy
Carlo Matulessy

Reputation: 995

Foursquare API get venue details with Retrofit for Android

I'm new to Retrofit for Android and I was wondering how to make a proper request when I want to obtain the venue details (https://developer.foursquare.com/docs/api/venues/details)

I know how to make a request like this: https://api.foursquare.com/v2/venues/search&v=20190211&near=Amsterdam

@GET("/v2/venues/search")
fun getVenueResults(
    @Query("near") near: String,
    @Query("limit") limit: Int,
    @Query("v") version: Int = 20190211,
    @Query("client_id") clientId: String = BuildConfig.FS_Client_ID,
    @Query("client_secret") clientSecret: String = BuildConfig.FS_Client_Secret
): Call<FoursquareAPIResponse>

But for the details you have to make a get request to:

https://api.foursquare.com/v2/venues/VENUE_ID

Where VENUE_ID is an ID of a venue. If I do something like this:

@GET("/v2/venues/")
fun getVenueDetails(
    @Query("") id: String,
    @Query("v") version: Int = 20190211,
    @Query("client_id") clientId: String = BuildConfig.FS_Client_ID,
    @Query("client_secret") clientSecret: String = BuildConfig.FS_Client_Secret
): Call<FoursquareAPIResponse>

It format the get request with venues/?=VENUE_ID instead of venues/VENUE_ID

Can someone help me with finding the correct way in Retrofit to format the get request to venue/VENUE_ID?

Upvotes: 1

Views: 587

Answers (1)

Tiago Ornelas
Tiago Ornelas

Reputation: 1119

Try this

@GET("/v2/venues/{venueId}")
fun getVenueDetails(
    @Query("v") version: Int = 20190211,
    @Query("client_id") clientId: String = BuildConfig.FS_Client_ID,
    @Query("client_secret") clientSecret: String = BuildConfig.FS_Client_Secret,
    @Path("venueId") id: String,
): Call<FoursquareAPIResponse>

Documentation - https://square.github.io/retrofit/2.x/retrofit/index.html?retrofit2/http/Path.html

Upvotes: 1

Related Questions