If you have questions or if you want to share your opinion about Aware IM post your message on this forum
#52608 by ddumas
Sun Jan 05, 2020 7:27 pm
I have reviewed the AwareIM Rest Service video a few times. I am trying to call the same weather service, just like in the video. I have created all necessary BO's (REST Service, Parameter, response, etc), and call a process to call the REST service. I am using the exact flow, objects, and code from the video. When I call the process I get an "Invalid API Key" from the weather service.

However, when I cut and paste the constructed URL (via a display message in awareim in the process) into the browser, it works perfectly, and returns the weather. The only difference is that I have to add the ? before the q=

h-t-t-p-://api.openweathermap.org/data/2.5/weather?q=Boston,us&APPID=1234

(my actual api key is not 1234), and the h-t-t-p does not have dashes


I have attached 2 of the important screenshots.

Any ideas?

Dave
Attachments
WeatherProcess.PNG
WeatherProcess.PNG (119.65 KiB) Viewed 1692 times
WeatherServiceBO.PNG
WeatherServiceBO.PNG (218.71 KiB) Viewed 1692 times
Last edited by ddumas on Thu Jan 09, 2020 2:57 pm, edited 1 time in total.
#52611 by ddumas
Mon Jan 06, 2020 1:28 am
I have searched through all the posts on this topic with the weather sample, and from what I have read, no one has gotten this to work end to end with json, as used in the tutorial video.

My gut feeling is that WeatherParameter.parameter never actually gets appended to the base URL string when the REQUEST SERVICE is called. I believe this is he case, because I can paste the URL into the browser with the correct &appid=REDACTED, and it returns the results fine.

Dave
#52613 by PointsWell
Mon Jan 06, 2020 4:49 am
The weather example video was built off an example that I built to teach myself how to use the API functionality. I seem to remember that there was a change to the ? functionality. Check out Jaymer's API posts as it was some specific example that he was implementing that required how the parameters get added that kicked off the change.
#52617 by ddumas
Mon Jan 06, 2020 12:23 pm
I had reviewed them all, and nothing works. Adding a ? after the base URL does nothing in this case.

Are you able to make other REST calls? If so, have you found that you have to prepend a ? after the base URL?

Dave
#52618 by ddumas
Mon Jan 06, 2020 1:18 pm
Just as I suspected: The WeatherService.parameter never gets appended to the final REQUEST SERVICE call string, even though I reference that explicitly in the "Take from Context" section in "Request body details".

Maybe this a bug?

From server output:

Calling REST URL http://api.openweathermap.org/data/2.5/weather .Parameter string is null Body string is:q=Boston,us&APPID=[redacted]
REST Service returned error {"cod":401, "message": "Invalid API key. Please see http://openweathermap.org/faq#error401 for more info."} with response code 401
{"cod":401, "message": "Invalid API key. Please see http://openweathermap.org/faq#error401 for more info."}
java.lang.Exception: {"cod":401, "message": "Invalid API key. Please see http://openweathermap.org/faq#error401 for more info."}
#52620 by BobK
Mon Jan 06, 2020 4:42 pm
I have not watched the Rest Service Video and the following is a quick and dirty example, but it works.

Here is my Rest Service set up:

restService.jpg
restService.jpg (139.93 KiB) Viewed 1643 times



and the following shows how I save the response:

restReply.jpg
restReply.jpg (236.71 KiB) Viewed 1643 times



The WeatherParameter BO has the city and country (London,uk) hard coded in the q attribute and the app ID hard coded in the APPID attributre.

My process that calls the service has the WeatherService, WeatherParameter and WeatherResult BOs as inputs.
The only rule is:
REQUEST SERVICE Weather OF WeatherService

The following result gets saved in WeatherResult.Result

{"coord":{"lon":-0.13,"lat":51.51},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10n"}],"base":"stations","main":{"temp":280.9,"feels_like":275.97,"temp_min":279.82,"temp_max":282.15,"pressure":1017,"humidity":76},"visibility":10000,"wind":{"speed":5.1,"deg":210,"gust":10.8},"rain":{"1h":0.25},"clouds":{"all":57},"dt":1578327004,"sys":{"type":1,"id":1414,"country":"GB","sunrise":1578297909,"sunset":1578326797},"timezone":0,"id":2643743,"name":"London","cod":200}
#52621 by ddumas
Mon Jan 06, 2020 5:14 pm
yep, that's how I forced mine to work also. At this point, It appears that the new v8.3+ feature to get the parameter string to use an object in context via the "Request Body" selection dialog does not work.

I will log a bug.

Thanks,

Dave
#52623 by BobK
Mon Jan 06, 2020 5:28 pm
ddumas wrote:yep, that's how I forced mine to work also. At this point, It appears that the new v8.3+ feature to get the parameter string to use an object in context via the "Request Body" selection dialog does not work.

I will log a bug.

Thanks,

Dave



It is my understanding that using "Request Body" option puts the data in the body of the request, not as part of the URL string.

I have successfully used the "Request Body" to call other Rest Services, but not this Weather service.
#52624 by ddumas
Mon Jan 06, 2020 5:47 pm
That's correct. In my case, in that dialog (that worked for you for a different service), I used a BO named "WeatherParameter", with the attribute named "parameter". WeatherParameter.parameter s/b in the context because in the calling process I create (and display) it.

In my case it never gets appended to the baseURL string when the service is called, as proven by the server output.

Very strange.

Dave
#52654 by BobK
Wed Jan 08, 2020 5:50 pm
In my case it never gets appended to the baseURL string when the service is called, as proven by the server output.


That is correct, your Parameter is not being appended to the baseURL because you are NOT telling AwareIM to do that. By using the "Request body" option you are telling AwareIM to put your Parameter into the body of the request.

Look at your server output:

Calling REST URL http://api.openweathermap.org/data/2.5/weather .Parameter string is null Body string is:q=Boston,us&APPID=[redacted]
REST Service returned error {"cod":401, "message": "Invalid API key. Please see http://openweathermap.org/faq#error401 for more info."} with response code 401
{"cod":401, "message": "Invalid API key. Please see http://openweathermap.org/faq#error401 for more info."}
java.lang.Exception: {"cod":401, "message": "Invalid API key. Please see http://openweathermap.org/faq#error401 for more info."}


notice the "Body string is:q=Boston,us&APPID=[redacted]". That shows that your Parameter is in the Body of the request.

The Weather Service your are trying to access requires the parameters to be in the URL. Since your parameters are in the body and not the URL, the service is not finding the APPID and returns error code 401 Invalid API key.

To access this Weather Service, you must use the AwareIM "URL-encoded string" option like in my first post.
#52656 by ddumas
Wed Jan 08, 2020 7:02 pm
So, I am still confused. In the end, all services, when called pass a URL string, correct? If not, how do I know which ones do and which ones do not. Even in the video for the weatcher, he shows the Body being used, and in the details dialog he defines the context BO.Attribute
#52695 by aware_support
Thu Jan 09, 2020 6:38 am
Not all services use URL string but all of them use some base URL. Parameters are either appended to the URL string (usually for GET requests) or specified in the body of the request (usually POST requests). It is up to a vendor, so you need to carefully read vendor's documentation to understand exactly how you should send the request.
#52698 by ddumas
Thu Jan 09, 2020 2:53 pm
Yes, thanks. FYI, in the AwareIM REST API video, a context BO is used as a json context object as a parameter to demonstrate the weather example from openweathermap. Since it is clear that openweathermap uses url string based parameters, the video is incorrect. I had spent many hours trying to get that to work using the context object following the video. Also, If you look at the video end to end, and try to think of a new user watching it, I think you might come to the conclusion that a new end to end video would really help new users, because of all the REST API features added across AwareIM versions. Just my opinion.
Thanks,
Dave

Who is online

Users browsing this forum: Google [Bot], MSN [Bot] and 15 guests