1
votes

I want to get data from API but get this error Here is an example of the url with coursesID params as 5012: https://dth.cohota.com/api/v1/calendar_events/?all_events=true&type=assignment&context_codes[]=course_5012

java.lang.IllegalArgumentException: URL query string "all_events=true&type=assignment&context_codes[]=course_{courseId}" must not have replace block. For dynamic query parameters use @Query.

And here is my code

 @GET("calendar_events/?all_events=true&type=assignment&context_codes[]=course_{courseId}")
    fun getCourseWithSyllabus(@Query("courseId") courseId: Long): Call<Course>

According to the official docs, I must use @Query, and i'm using it, but i also get the error. Thank you for your replies.

1

1 Answers

0
votes

The error means that you can only have hardcoded query params i.e. the stuff after ?. For dynamic query params, use something like

@Query("context_codes[]") contextCodes

and supply a value like "course_$courseId" as its value.

You can examine Retrofit source to learn where the exception comes from in detail.