I'm trying to access alert information from api.weather.gov, and it works fine in google. However, when I try accessing the URL in app inventor, it gives me the following error:
Does app inventor block this API, or does the API not work with app inventor?
The exact URL I am trying to access is https://api.weather.gov/alerts/active.
Here is my code:
This isn't a block enforced by App Inventor. It just tries to do whatever you instruct it to do. Given that you get a result from the weather service, it shows that they are the one returning an error. One issue I'll note in your blocks is that you check whether responseCode is 403 or not. If an HTTP request is successful, the responseCode from the server will be 200. HTTP 403 indicates that the request is forbidden. You realistically want to check whether the responseCode is 200 and proceed accordingly.
I think we need to understand why you're receiving an error response. Totally independently, we have a student working on this particular API and we have gotten things working there. My immediate guess is that you need to be sending an Authorization header by setting up the RequestHeaders property properly. When you say you are testing this in your browser, are you using a Swagger-style interface or are you just opening the URL directly?
So I poked around at this and I think the issue is that the server wants a User-Agent header for some purpose. Most clients include one by default by App Inventor does not since we don't know what the final name of your app will be. For example:
After fixing that I did encounter a more serious bug that is causing an exception to be thrown when parsing the GeoJSON into features. I think it should be fixable as part of the next companion update.
yes exactly... therefore reading the documentation helps...
thank you @SteveJG
Authentication
A User Agent is required to identify your application. This string can be anything, and the more unique to your application the less likely it will be affected by a security event. If you include contact information (website or email), we can contact you if your string is associated to a security event. This will be replaced with an API key in the future.
Press the Web button to request from the Web. It might take a couple of seconds for a response. When the display changes, press the JSON button to parse it as JSON and launch a tree climb into it.