Itunesconnect api JWT problem

Hey, I'm trying to use https://developer.apple.com/documentation/appstoreconnectapi/

Heres the code to generete JWT token:

func main() {

  bytes, err := ioutil.ReadFile("AuthKey.p8")
  if err!=nil {
  fmt.Println(err)
  }

  block, _ := pem.Decode(bytes)
  key, err := x509.ParsePKCS8PrivateKey(block.Bytes)
  if err != nil {
  log.Fatal(err)
  }

  token := jwt.NewWithClaims(jwt.SigningMethodES256, jwt.MapClaims{
  "iss": iss,
  "exp": time.Now().Unix()+6000,
  "aud": "appstoreconnect-v1",
  })

  token.Header["kid"] = kid

  tokenString, err := token.SignedString(key)
  if err != nil {
  log.Fatal(err)
  }
  fmt.Println(tokenString)

}


I'm getting the JWT code but when I'm trying to use it got 401 NOT_AUTHORIZED

Replies

Hello cawakharkov,

What is the Access level that the App Store Connect Key has? Does it have the right permissions for the API resource that you are trying to access? I would double check that these line up correctly as if they do not you will get the above error.


Hopefully this helps!