3

I'm using this code to get all apps in App Store Connect:

let jwt = ...
var request = URLRequest(url: URL(string: "https://api.appstoreconnect.apple.com/v1/apps")!)
request.setValue("Bearer \(jwt)", forHTTPHeaderField: "Authorization")
let session = URLSession(configuration: .ephemeral)
let task = session.dataTask(with: request) { data, response, error in
    if let error = error {
        print(error)
    } else if let data = data {
        print(String(data: data, encoding: .utf8))
    }
}
task.resume()

But the response is an error status: 400, code: ENTITY_INVALID, title: JSON processing failed. What entity is this error referring to? And what JSON is invalid? The JWT token seems to be fine, since when using a random value I get an error 401 NOT_AUTHORIZED.

3
  • See this information. Specifically "Identify Errors with the Request Entity" Commented Feb 14, 2024 at 21:09
  • In my case, I was including an empty array for the scope member of the claim portion of the JWT. If no scope is needed, do not include that member at all Commented Feb 14, 2024 at 21:16
  • Thanks! That seems to be the reason. You may want to add this as an answer. Commented Feb 16, 2024 at 18:23

1 Answer 1

2

As per my comment in the question, if no scope is required, you need to omit it from the claim portion of the JWT, i.e. instead of (for example):

{
    "iss": "57246542-96fe-1a63-e053-0824d011072a",
    "iat": 1528407600,
    "exp": 1528408800,
    "aud": "appstoreconnect-v1",
    "scope": [
    ]
}

Use:

{
    "iss": "57246542-96fe-1a63-e053-0824d011072a",
    "iat": 1528407600,
    "exp": 1528408800,
    "aud": "appstoreconnect-v1"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.