Apple have published docs on this topic now and also modified the API so that now your JWT subject has to be sub and not subject as I was able to get away with in my first code example.
Post
Replies
Boosts
Views
Activity
SUCCESS! Had a labs call with two Apple engineers and they set me on the right path.
This is what your JWT should look like:
var privateKey = fs.readFileSync("YOU KEY FILE FROM DEVELOPER CENTER.p8");
var token = jwt.sign(
{
subject: "APP ID",
},
privateKey,
{
jwtid: "YOUR TEAM ID.YOUR APP ID",
issuer: "TEAM ID",
expiresIn: "1h",
keyid: "KEY ID",
algorithm: "ES256",
header: {
id: "YOUR TEAM ID.YOUR APP ID",
},
}
);
// id is teamid.serviceid
const url =
"https://weatherkit.apple.com/api/v1/weather/en/51.677612/-2.937941?dataSets=currentWeather&timezone=Europe/London";
const config = {
headers: { Authorization: `Bearer ${token}` },
};
const { data: weatherData } = await axios.get(url, config);
Getting the id on the header is the trick.
I have made a YouTube video and example app but it won't let me post the link, the youtube video id is: 7mg42_Fix9k
Looks like there is a url issue? If I use the urls in the docs:
https://weatherkit.apple.com/api/v1/weather/en
then I get a 500.
If I use the url as in the video
https://weatherkit.apple.com/1/weather/
then I get a 401
Anyone get this working yet?
I'm getting a 500 with a node app