简体   繁体   中英

Apple Store Connect Api http request returns error 404 not found

I'm having some issues establishing a connection with this API, in concrete https://api.appstoreconnect.apple.com/v1/salesReports . But I'm receiving the error 404 not found as a response to my request. The real problem is that this same code, with the same parameters, was working yesterday.

I have been reading, and sometimes this API stops working, but I found here https://developer.apple.com/system-status/ that, this cannot be.

I also have thought that, as I'm using tokens to establish this connection, maybe they have expired (but I haven't been able to find any info related to this).

Any idea why this is happening?

I leave here my code, just to verify, that this is not the problem.

First the token generation function code (I'm hiding some parameters for privacy reasons)

public static string GenerateAppStoreJwtToken(string privateKey)
        {
            var header = new Dictionary<string, object>()
            {
                { "alg", "ES256" },
                { "kid", "XXXXXXXXXX" },
                { "typ", "JWT" }
            };

            var payload = new Dictionary<string, object>
            {
                { "iss", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" },
                { "exp", DateTimeOffset.UtcNow.AddMinutes(15).ToUnixTimeSeconds() },
                { "aud", "appstoreconnect-v1" }
            };

            CngKey key = CngKey.Import(Convert.FromBase64String(privateKey), CngKeyBlobFormat.Pkcs8PrivateBlob);

            string token = JWT.Encode(payload, key, JwsAlgorithm.ES256, header);

            return token;
        }

And here is my function that makes the request. (Also hiding some parameters for privacy reasons)

private async Task GetHttpRequest(string privatekey)
        {
            
                //We generate the token
                TokenClass token = new TokenClass(privatekey);

                //Configuration of the requesting
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.token);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/a-gzip"));
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                //Init the request
                Stream response = await client.GetStreamAsync("https://api.appstoreconnect.apple.com/v1/salesReports" +
                    "?filter[frequency]=DAILY" +
                    "&filter[reportSubType]=SUMMARY" +
                    "&filter[reportType]=SALES" +
                    "&filter[vendorNumber]=XXXXXXXX");

            }

The error that outputs is:

Unhandled Exception: System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found).

I find out the issue. This API creates the report each day at specific time, so if you ask for a report that hasn't been created yet, the response would be error 404 (Not Found).

This was my error, but be aware that there are many conditions to use these filters.

Check the following link, all the conditions are explained https://help.apple.com/app-store-connect/#/dev8a5831138 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM