I have an API call to display search item in recyclerview. So i'm using retrofit and kotlin coroutines for the API call. But the network call returning the forbidden error
{protocol=h2, code=403, message=, url=https://www.blibli.com/backend/search/products?&searchTerm=samsung&start=0&itemPerPage=24}
The url is correct, because i can get response using volley library, but i need to get the response from retrofit.
This is interface class
interface ApiService {
@GET("products")
suspend fun getItems(@Query("searchTerm") item : String,
@Query("start") start : String,
@Query("itemPerPage") page : String) : Example
}
class SearchViewModel : ViewModel() {
fun getItems() : LiveData<Example?> {
System.out.println("========== activated")
var response = liveData(Dispatchers.IO) {
try {
var items = Api.getRetrofit()?.getItems("samsung", "0","24")
emit(items)
System.out.println("========== retrofit $items")
}catch (ex: Exception){}
catch (ex: Throwable){}
catch (ex: HttpRetryException){}
}
return response
}
}
class MainActivity : AppCompatActivity() {
lateinit var viewModel : SearchViewModel
var adapter : SearchAdapter? = null
var otherOffer : OtherOfferings? =null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_search)
viewModel = ViewModelProviders.of(this).get(SearchViewModel::class.java)
viewModel.getItems().observe(this, Observer {
System.out.println("========= ${it}")
})
}
}
Someone please help me, i don't know what's wrong with my code, the same code works with other APIs.