Response 400 on API REST - App iOS


Hi,

I have a problem when running my application on iOS devices, when I start I make two API Rest calls (login, user data recovery), and it makes them correctly, but when trying to make other calls, including user data recovery , I get an error 400, attached images of log and project.


thanks



Hi Carles,

HTTP code 400 for bad request. so might be there is some mistake in your request. Is it possible that after calling login api, for other apis you need to pass some authentication key etc with every request.

Hi Carles,

I have checked your oml and noticed that your request don't need any request parameter and you are only passing token in authorization header. But source of token is different while calling get resource API. In your login screen you are passing that from your screen local variable and on Perfil you are passing it from local entity. 

So possibly you have different token on both places and because of that it is working on one place but not on other.

You can try two things to check the exact issue.

  1. Pass a hardcoded token on both place if it workes
  2. Add debug point where you are calling get resource API in your client action and check the token value.

Hi,

Thanks for the help, I have the problem only when I run the application on iOS device, on Chrome and Android devices it works perfectly.

Hi Carles,

Since the REST call is made via the server, the actual device can't really be the problem, unless you are passing parameters that are device-dependent. Please increase the logging level of the REST API, and look at the differences between what's sent from Android vs. iOS.

Hi,

I have tried and see that the same token is sent on all calls, but I cannot see the complete call, there is some way to see the complete call in log

thanks

Hi Carles,

Did you follow the instructions I linked above? In that case you should be able to see the complete call.

Hi,
Among the tests I had done I had already done the previous steps, but I only see complete traces in calls ok, but in these we.

Rest NO OK!!! (Users Screen)

REST API OK (login Screen)

Hi Carles,

The only thing I can think of that makes it return a 400 instead of the 200 from the call, is that there's an OnAfterResponse that causes this (i.e. sets the 400). Otherwise I'd create a test module that makes the same call with hard coded values, and see whether it goes wrong as well, just to eliminate other variables.

But what seems curious to me is that at first the call is made correctly and then the same call (copied) I made it wrong.

What do you mean by "first call" and "same call (copied)"?

Create the first call (run client) on the loggin screen and then (Ctrl + c) and I have pasted(Ctrl +v)on the profile screen.

You mean inside your Module? Copy/pasting shouldn't have any effect on the call itself.

But again, I'm not sure what you did and when and in what order, and what goes right and what goes wrong, as your descriptions are very patchy. I'd love to help, but without any further info I'm afraid this is about as much as I can do.

First of all thanks for all the effort invested.

When I login, I also retrieve user profile data (common login screen), this makes it correct, then it goes to the Main screen, from this moment the calls to the Rest APIs stop working. It is as if by leaving common control, calls to api stopped working.

Did you check the Integration Log for the call not working? Because in the post above, you show the Error Log first, then the Integration Log. It would be nice to have the Integration Log for both the call that goes ok, and the call that fails.

Solution

Hi,

Thanks for all the effort.

I deleted the whole project and started again and for now all the calls are working.

thanks

Solution

Really weird this happened, but thanks for reporting back :). Happy coding!