Hi all,
I am facing similar issues with my JWT. I generate the token using the code below:
Map<String,Object> jwtHeader = new HashMap<>();
jwtHeader.put("alg","ES256");
jwtHeader.put("kid","myKeyId");
jwtHeader.put("typ","JWT");
Map<String,Object> appleJwtPayload = new HashMap<>();
appleJwtPayload.put("sub","user");
appleJwtPayload.put("iat",System.currentTimeMillis() / 1000L);
appleJwtPayload.put("exp",System.currentTimeMillis() / 1000L + 60 * 15);
appleJwtPayload.put("aud","appstoreconnect-v1");
appleJwtPayload.put("bid","bundleIdentifier");
PrivateKey appleKey = getPrivateKey(APPLE_PRIVATE_KEY_PATH,"EC");
String accessToken = Jwts.builder()
.setClaims(appleJwtPayload)
.setHeader(jwtHeader)
.signWith(appleKey)
.compact();
System.out.println(accessToken);
I can use the generated token just fine when using the /apps endpoint like :
curl --location 'https://api.appstoreconnect.apple.com/v1/apps' \
--header 'Authorization: Bearer my_JWT_Token'
But when I use the same token in
curl --location 'https://api.appstoreconnect.apple.com/v1/analyticsReportRequests ' \
--header 'Authorization: Bearer my_JWT_Token' \
--header 'Content-Type: application/json' \
--data '{
"data": {
"type": "analyticsReportRequests",
"attributes": {
"accessType": "ONGOING"
},
"relationships": {
"app": {
"data": {
"type": "apps",
"id": "6472717634"
}
}
}
}
}'
I always get a 401 error. Any ideas on what am I doing wrong ?
Many thanks in advance.