2

I am trying to access API of Apple Music API

(https://developer.apple.com/documentation/applemusicapi).

After creating the JWT developer token, when i try to access the API, An error of 401 - Unauthorized occurs.

I am doing it in the following way :

  1. Registering a new music identifier (https://help.apple.com/developer-account/#/devce5522674?sub=dev0416b9004)

  2. Creating a MusicKit identifier and private key (https://help.apple.com/developer-account/#/devce5522674) also downloading the private key file.

  3. Getting the Kid (Key Id) and issuer (Team Id) .

  4. Running the following code to generate the token :

const jwt     = require("jsonwebtoken");

const privateKey = fs.readFileSync("AuthKey_KEY_ID.p8").toString();
const teamId     = TEAM_ID_HERE;
const keyId      = KEY_ID_HERE;

const jwtToken = jwt.sign({}, privateKey, {
  algorithm: "ES256",
  expiresIn: "120d",
  issuer: teamId,
  header: {
    alg: "ES256",
    kid: keyId
  }
});

console.log(jwtToken);```

And after that checking the code using the curl command : 

```curl -v -H 'Authorization: Bearer [developer token]' "https://api.music.apple.com/v1/catalog/us/songs/203709340"```




I am not sure what i am missing here. is it something related to access or is it my code.
P.S : I am the Account Holder, so it is not an issue related to role.

Thanks
Marwen Doukh
  • 1,946
  • 17
  • 26
rajat_bt
  • 21
  • 3

0 Answers0