I have an API endpoint that is supposed to send a one-time password to a user email. I try it on postman and it works just fine. However it doesn't give any response in the code I am new to this, can anyone give me an answer. Here is my code...
// call to get OTP
public void makeApiCallForVerification(Context context, String email,String token){
mApiServiceVerification = RetrofitInstance.getRetroClientWithToken(token).create(APIService.class);
System.out.println("token is: " token);
mCallVerification = mApiServiceVerification.CheckUserVerification();
mCallVerification.enqueue(new Callback<UserVerificationResponse>() {
@Override
public void onResponse(Call<UserVerificationResponse> call, Response<UserVerificationResponse> response) {
mLiveDataVerification.postValue(response.body());
LiveDatauserVerificationStatus.postValue(response.code());
if(response.body() != null) {
Log.d(TAG, "onResponse: " response.body().toString());
SweetAlertDialog dialog= new SweetAlertDialog(context, SweetAlertDialog.SUCCESS_TYPE);
dialog.setTitleText("Verification Sent to \n" email)
.setContentText("Check your Email Inbox")
.setNeutralButtonTextColor(Color.parseColor("#297545")).setCancelable(false);
dialog.show();
try{
int OTP = response.body().getDataSentInEmail().getOtpNumber();
updateVerificationStatus( context,OTP,0);
OTPCodeLiveData.postValue(String.valueOf(OTP));
LiveDatauserVerificationStatus.postValue(0);
}catch (Exception e){
Log.d(TAG, "onResponse: err " e.toString());
e.printStackTrace();
}
}
}
@Override
public void onFailure(Call<UserVerificationResponse> call, Throwable t) {
Log.d(TAG, "onFailure: " t);
System.out.println(call);
LiveDatauserVerificationStatus.postValue(-1);
ErrorLiveData.postValue(t.toString());
Log.d(TAG, "onResponse: " t.toString());
}
});
}
//on the Interface class
@Headers("Accept: application/json")
@GET("user/otp")
Call<UserVerificationResponse> CheckUserVerification();
CodePudding user response:
You can try it
@Headers("Content-Type: application/json")
CodePudding user response:
Try changing APIService(interface) class like this("/" before user at @GET)
@Headers("Accept: application/json")
@GET("/user/otp")
Call<UserVerificationResponse> CheckUserVerification();
