400 : bad gateway error when requesting analytics reports

Hello, I have tried this method

curl -X POST 
      -H "Authorization : Bearer [my_Token]" 
      -H "Content-Type: application/json" --data-binary @"data.json"   
      https://api.appstoreconnect.apple.com/v1/analyticsReportRequests

with the contents of "data.json" being :

{
  "data": {
    "type": "analyticsReportRequests",
    "attributes": {
          "accessType": "ONE_TIME_SNAPSHOT"
    },
    "relationships": {
      "app": {
        "data": {
          "type": "apps",
          "id": "[my_appid]"
        }
      }
    }
  }
}

in order to send a POST request reports request to the apple store connect API, as per this https://developer.apple.com/documentation/appstoreconnectapi/post-v1-analyticsreportrequests documentation, but with no success. I have made sure my JWT is correct :

headers = {
        "alg": "ES256",

        "kid": [my_private_keyid],

        "typ": "JWT"
    }
payload = {
    "iss": [my_issuer_id],
    "iat": int(date_emission.timestamp()),  
    "exp": int(date_expiration.timestamp()), 
    "aud": "appstoreconnect-v1",
    "bid": "[my_bundleid]"
}

as per this https://developer.apple.com/documentation/appstoreserverapi/generating-json-web-tokens-for-api-requests documentation.

I have also made sure my key is an admin key as it is required in order to send such a request, and I have used JSON online verificators to make sure my JSON is correct, as I was expecting it to be a JSON related issue. I really can't seem to understand why I only get 400 : bad gateway responses, any help would be appreciated on the matter.

Answered by tibitb in 823559022

Solved : I ended up using python which worked just fine

Ok, so, after a bit of back and forth, here's where I stand :

curl --location 'https://api.appstoreconnect.apple.com/v1/analyticsReportRequests' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer [my_token]' \
--data '{
        	"type": "analyticsReportRequests",
        	"attributes": { 
           	"accessType": "ONGOING"
        	},
        	"relationships": {
           	"app" : {
              	"data" : {
                 	"type" : "apps",
                 	"id" : "[my_appid]"
              	}
           	}
        	} 
    	}'

I have changed up my request such that it now looks like this, and I've got a new issue :

{
    "errors": [
        {
            "id": "[id]",
            "status": "422",
            "code": "ENTITY_UNPROCESSABLE",
            "title": "The request entity is not a valid request document object",
            "detail": "Unexpected or invalid value at 'type'.",
            "meta": {
                "position": {
                    "row": 2,
                    "column": 22
                }
            }
        }
    ]
}

Doesn't really feel like I've made any progress, but I'm now getting a 422 error response, and I really don't see any way out of this. Any help at all would be appreciated.

Accepted Answer

Solved : I ended up using python which worked just fine

Hey,

Can you share the python code for reference? I have tried multiple python codes and facing multiple errors to fetch the analytics reports.

400 : bad gateway error when requesting analytics reports
 
 
Q