Post

Replies

Boosts

Views

Activity

Reply to WeatherKit REST API 401 error: { reason: 'NOT_ENABLED' }
This is the response from the server that I forgot to add yesterday response: { status: 401, statusText: 'Unauthorized', headers: AxiosHeaders { server: 'AppleHttpServer/0716b0c1a3a0f9c2fa220619c9901ea42a9aac04', 'x-frame-options': 'DENY', 'strict-transport-security': 'max-age=31536000; includeSubDomains, max-age=31536000', 'x-xss-protection': '1; mode=block', 'access-control-allow-origin': '*', 'x-content-type-options': 'nosniff', 'content-security-policy': "default-src 'self';", 'x-request-id': '6d6f842a-cb5e-4e28-abd8-e4486faa87ec', 'x-b3-traceid': '4d098ad911e603a4', date: 'Sat, 21 Jan 2023 20:32:32 GMT', 'x-cache': 'TCP_MISS from a23-220-165-69.deploy.akamaitechnologies.com (AkamaiGHost/10.10.3-45298580) (-)', connection: 'close' }, config: { transitional: [Object], adapter: [Array], transformRequest: [Array], transformResponse: [Array], timeout: 0, xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN', maxContentLength: -1, maxBodyLength: -1, env: [Object], validateStatus: [Function: validateStatus], headers: [AxiosHeaders], method: 'get', url: 'https://weatherkit.apple.com/api/v1/weather/en/37.323/122.032?dataSets=currentWeather', data: undefined }, request: <ref *1> ClientRequest { _events: [Object: null prototype], _eventsCount: 7, _maxListeners: undefined, outputData: [], outputSize: 0, writable: true, destroyed: false, _last: true, chunkedEncoding: false, shouldKeepAlive: false, maxRequestsOnConnectionReached: false, _defaultKeepAlive: true, useChunkedEncodingByDefault: false, sendDate: false, _removedConnection: false, _removedContLen: false, _removedTE: false, strictContentLength: false, _contentLength: 0, _hasBody: true, _trailer: '', finished: true, _headerSent: true, _closed: false, socket: [TLSSocket], _header: 'GET /api/v1/weather/en/37.323/122.032?dataSets=currentWeather HTTP/1.1\r\n' + 'Accept: application/json, text/plain, */*\r\n' + 'Authorization: Bearer eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjlETDRYVVNOVTYiLCJpZCI6IjU5WDlYVVo5OTQudm95YWdlci5mYWlyV2VhdGhlckZyaWVuZHMifQ.eyJzdWJqZWN0Ijoidm95YWdlci5mYWlyV2VhdGhlckZyaWVuZHMiLCJpYXQiOjE2NzQzMzMxMTgsImV4cCI6MTY3NDMzNjcxOCwiaXNzIjoiNTlYOVhVWjk5NCIsImp0aSI6IjU5WDlYVVo5OTQudm95YWdlci5mYWlyV2VhdGhlckZyaWVuZHMifQ.Nft6qHN8rWecBwKyvBBa6MmehrqA0UotW44bKm8UGld0GVKN9Jnn6YYPOesYRHcpXMb7k6auExbvqynRS2TFeQ\r\n' + 'User-Agent: axios/1.2.3\r\n' + 'Accept-Encoding: gzip, compress, deflate, br\r\n' + 'Host: weatherkit.apple.com\r\n' + 'Connection: close\r\n' + '\r\n', _keepAliveTimeout: 0, _onPendingData: [Function: nop], agent: [Agent], socketPath: undefined, method: 'GET', maxHeaderSize: undefined, insecureHTTPParser: undefined, path: '/api/v1/weather/en/37.323/122.032?dataSets=currentWeather', _ended: true, res: [IncomingMessage], aborted: false, timeoutCb: null, upgradeOrConnect: false, parser: null, maxHeadersCount: null, reusedSocket: false, host: 'weatherkit.apple.com', protocol: 'https:', _redirectable: [Writable], [Symbol(kCapture)]: false, [Symbol(kBytesWritten)]: 0, [Symbol(kEndCalled)]: true, [Symbol(kNeedDrain)]: false, [Symbol(corked)]: 0, [Symbol(kOutHeaders)]: [Object: null prototype], [Symbol(kUniqueHeaders)]: null }, data: { reason: 'NOT_ENABLED' } }
Jan ’23
Reply to WeatherKit REST API 401 error: { reason: 'NOT_ENABLED' }
Solving my own thread: The issue here is in the very first line of my code: var jwtToken = jwt.sign({ subject: 'my.company' }, "subject" should be "sub" var jwtToken = jwt.sign({ sub: 'my.company' }, That was literally it. Apple must have changed the expected format of the JWT, because all the videos about the API after it was released show developers using "subject". Hope this helps someone in the future.
Jan ’23
Reply to WeatherKit REST API WeatherAlert data question
Welp, I figured it out. The answer is that they come in the form of a weatherAlerts {} objects, and within that are alerts. The object looks like weatherAlerts: { name: 'WeatherAlertCollection', metadata: { attributionURL: 'https://weatherkit.apple.com/legal-attribution.html', expireTime: '2023-02-24T02:11:03Z', language: 'en-US', latitude: 38.102, longitude: -121.523, providerName: 'National Weather Service', readTime: '2023-02-24T02:06:03Z', reportedTime: '2023-02-24T02:06:03Z', version: 1 }, detailsUrl: 'https://weatherkit.apple.com/alertDetails/index.html?ids=6f7b2352-32f7-5bec-8ac8-ca076081a8a6&lang=en-US&timezone=America/Los_Angeles', alerts: [ [Object] ] } And the alerts object looks like this { "name": "WeatherAlertSummary", "id": "6f7b2352-32f7-5bec-8ac8-ca076081a8a6", "areaId": "caz018", "areaName": "Carquinez Strait and Delta", "attributionURL": "https://alerts.weather.gov/cap/wwacapget.php?x=CA126637448CAC.WindAdvisory.1266375FF640CA.STONPWSTO.5ff78b05a939c15640f1e82f369abae7", "countryCode": "US", "description": "Wind Advisory", "token": "WIND_ADVISORY", "effectiveTime": "2023-02-23T20:35:00Z", "expireTime": "2023-02-25T00:00:00Z", "issuedTime": "2023-02-23T20:35:00Z", "eventEndTime": "2023-02-25T00:00:00Z", "detailsUrl": "https://weatherkit.apple.com/alertDetails/index.html?ids=6f7b2352-32f7-5bec-8ac8-ca076081a8a6&lang=en-US&timezone=America/Los_Angeles", "phenomenon": "Wind", "precedence": 0, "severity": "minor", "significance": "advisory", "source": "National Weather Service", "eventSource": "US", "urgency": "expected", "certainty": "likely", "importance": "low", "responses": [] } However, the reason I was having such a hard time finding any alerts in all of my testing is because the country code and timezone query parameters are required in the request URL. That wasn't explained in the docs, as far as I can tell, and that's incredibly disappointing and frustrating. I hope that can be made more obvious for future developers. Hope this post itself is helpful for anyone stuck.
Feb ’23