Weatherkit REST API is throwing 401 errors {'reason': 'NOT_ENABLED'}

I have a script which fetches observations from weatherkit rest API which was working fine till morning. Suddenly I am getting {'reason': 'NOT_ENABLED'} error. I haven't changed anything. My key still has access to weatherkit. Any idea what happened here?

Same problem here with the REST API since a couple of weeks. We got errors on approx 50% of all WeatherKit calls too.

Need to start looking for an alternative APIs soon, this API does not seem fit for production use. Any recommendations?

PROBABLE SOLUTION TO THE 401 ISSUE WITH WEATHERKIT:

For everyone seeing this issue, what is likely the case is that you're generating the bearer token with a now timestamp and fixed (probably short) expiry. If you're rounding a millisecond timestamp to seconds to create that token you will likely see a certain percentage of requests with a JWT that is a few milliseconds too young to be valid yet (depending on exact time-shift with Apple's servers). Generate the token with a few seconds negative offset versus "now" and you'll be fine.

This worked like a charm for us.

An update. Seems like maybe @Hi_Thomas solution was a coincidence, as someone else suggested. I am getting 401 errors again starting today. Why is Apple not saying anything about this? They are on the boards answering other questions. But they ignore this issue that is clearly the biggest cause of concern. I'm happy if they say we devs are doing something wrong. But the silence is unprofessional. Here are things you can say:

  1. We are looking into it but don't know anything yet.
  2. We've looked into it, and everything is fine on our end
  3. We have isolate the root cause and are working on a fix, though we don't have a timeline for when we will deploy a fix.
  4. We decided not to look into it.

Even 4. is better than nothing.

same here, none of those solutions I can find work for me

Weatherkit REST API is throwing 401 errors {'reason': 'NOT_ENABLED'}
 
 
Q