Beginner trying to authorize Apple Music API request

I'm a new programmer and I'm trying to work with the Apple Music API as a way to teach myself. So this is probably a dumb question, but I'm using the docs to figure out how to make a request, and I think I have the token all set with the key ID and UNIX time and all that. But I get a 401 Unauthorized back when I send a GET request with it, and I'm having trouble understanding what the docs say about authorization. It says to pass Authorization: Bearer in the header. I'm trying to do that in Insomnia but it must be over my head. I'm guessing there's something obvious that I'm doing wrong, but I'm not sure what. Hoping someone here will take one look at it and be able to tell me. I tried it a few different ways but this is the gist.

The REST API requires that you pass your developer token after the word "Bearer" in that header:

https://developer.apple.com/documentation/applemusicapi/generating_developer_tokens#3001394

Is that what you're doing?

@Polyphonic Sorry for the delay, I was expecting an email notification if anyone replied, my fault.

I guess what confuses me is that I'm creating the token, right? So how do I pass the developer token after the word 'Bearer' in the header of that token? It's not the key ID, I'm assuming.

@hntdhs you can create an auth token with something similar to this:

const generateAppleMusicToken = async ({
  filePath,
  issuer,
  kid,
}: { filePath: string; issuer: string; kid: string }) => {
  console.log('Generating apply music token...')
  const privateKey = await readFile(filePath, { encoding: 'utf-8' })

  return jwt.sign({}, privateKey, {
    issuer,
    expiresIn: '180d',
    header: {
      alg: 'ES256',
      kid,
    },
  })
}

you should have a .p8 file if you've signed up as an apple developer and created a key. For more info on JWTs, check out https://jwt.io/introduction

Beginner trying to authorize Apple Music API request
 
 
Q