I set up an API and cloud deployed it to get the current weather in my city with

co=CloudDeploy[APIFunction[{},ResponseForm[QuantityMagnitude[UnitConvert[=current temperature in new york city,"DegreesCelsius"]],"JSON"]&],Permissions->"Public"]

This works perfectly and I'm able to access the output with an http request.

Only problem is that the value returned for temperature seems to be stuck at the value of when I originally deployed the API.

Is the problem maybe just the actual frequency the data is updated on wolfram's side, or do I need to change something in the code?


PS: I'm new no Mathematica and not sure what's the best way to paste my input code here, so just to explain, for the =current temperature in new york city I used the natural language processing function in Mathematica.

Update: Without relying on natural language input, the line above can be replaced with the following. Thanks Syed for pointing this out.

co=CloudDeploy[APIFunction[{},ResponseForm[QuantityMagnitude[UnitConvert[AirTemperatureData[Entity["City", {"NewYork", "NewYork", "UnitedStates"}]],"DegreesCelsius"]],"JSON"]&],Permissions->"Public"]
  • 1
    $\begingroup$ Explore Delayed in conjunction with CloudDeploy. $\endgroup$
    – Syed
    Nov 11, 2021 at 18:40
  • $\begingroup$ Thank you @Syed, that looks like exactly what I need. However, it seems like this changed the format of the API json output as well. It used to have a Value field, but that is now gone. Any ideas? $\endgroup$
    – Mike
    Nov 11, 2021 at 19:23
  • $\begingroup$ Why do you think that the value returned from the API is stuck? It's a weather data and will take time to change. Try deploying something that changes instantly like time and see it will work. I don't see any issue with your API. Try: api = CloudDeploy[APIFunction[{}, ResponseForm[DateString["ISODateTime"], "JSON"]&]]; Lookup[URLExecute[api, "JSON"],"Result"] $\endgroup$
    – dsingh
    Nov 12, 2021 at 5:27
  • 1
    $\begingroup$ Try: AirTemperatureData[ Entity["City", {"NewYork", "NewYork", "UnitedStates"}]] if you don't want natural language input. $\endgroup$
    – Syed
    Nov 12, 2021 at 6:25
  • $\begingroup$ @dsingh you're right, I was expecting it to update at a higher frequency but it makes sense that it wouldn't be too fast, thanks! $\endgroup$
    – Mike
    Nov 12, 2021 at 16:32


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.