I am trying to make a basic REST API call that retrieves and displays the weather data for a city using its name when a button is clicked. I have managed to get the call to work and the data to be displayed, but only when a default value is used as the city name.
I have an input widget configured as shown below that I want to retrieve a value from and send in place of the default value when the call is made, but I have been unable to do so.
My button is configured like this and is intended to call the Retrieve_Weather client action when clicked and send the value of city2 to the API URL so that the correct city can be retrieved.
The Retrieve_Weather client action is set up like this:
My REST API method is set up like this:
And my GetWeather server action is set up like this:
The API call works when a default value is provided, but I need to be able to use the value of the input widget, inCity, in place of the {city} part of the API URL. This is the part I have been unable to get to work.
If anyone is able to help it would be greatly appreciated.
I am very new to OutSystems development so please forgive my ignorance. I can provide any other information as required. Thank you.
I have found a fix. My Retrieve_Weather client action needed an assignment operator to assign the returned value to the output parameter of my DataAction1 as shown below. The correct data for each city is now being displayed.
Have you found any error in the "response" or in the OutSystems logs ?
The "GetWeather" has a warning. Have you found why?
Regards
Graça
Hi Maria, thanks for getting back to me.
The warning on the GetWeather server action:
"You're exposing a Server Action for public access and without authentication. Consider removing the Anonymous Role from this Screen."
The app I am building does not need to be secure so this is not a problem for me.
Apologies, as I am quite new to the platform I do not know how to access the OutSystems logs, how can I access those? I have not noticed an error in the response, but it is possible I just haven't been able to see the error if it is there.
The response itself works fine when a default value is provided for the API call.
Sam
They are in the Service Center portal from your environment.
In service studio menu you find a link to the service center login screen
you can enter with the same user and password you use in the service studio.
In the tab "Monitoring" are the logs, ErrorLog and GeneralLog
Hi Maria
My error logs show a long list of "400 bad request errors". This is the error I get when I try and make the API call either without inputting a value in the input widget or entering certain other invalid city names. The error seems very inconsistent in the sense that certain values, even if not valid cities, produce the error and others do not. Leaving the input blank gives the error every time.
Please let me know if you require any further information. Thank you
You have to review the information you have about the API, and see if you are not missing any thing. (something like use a trial api address that worked only with a specific value ... happened to me)
You also can debug the application to see exactly what are you sending to the "GetCurrent" action parameter.
And try it with the default value that you say is working.
I cannot help you more than this.
Sorry
No worries, appreciate the response :)
Good that you have found a fix, but reading up on this whole thread.. it should be:
DataAction1, the Fetch property on: 'Only on demand'If you open the page with an already filled in city2 variable, set the Fetch property on: 'On start'
Within the DataAction1, you call the Weather API, by having the city2 as variable.And you set the DataAction1.Response = GetCurrent.Response
Within the Retrieve_Weather client action you only have to Refresh DataAction1
If you want, provide an OML with your current solution, and I will upload the fixed version.
Hi Jeroen
Thank you for the response. I have uploaded the .oap file of my application in this reply. Is this what you were referring to?
Sure, I've edited the module.
Here it is, you can open the OML and include it in your application, or copy/paste the screen.
You also need to look into the response structure and API OnAfterResponse.I've added an Error structure.
When you've entered a text that does not correspond to a valid location, the API returns an error code instead (with a message).
I've fixed the module for now, to have you at least view the messages that you receive from the API.
Thank you, much appreciated :)