简体   繁体   English

Apple Store Connect Api http 请求返回错误404未找到

[英]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 .我在与这个 API 建立连接时遇到了一些问题,具体是 https://api.appstoreconnect.apple.com/v1/salesReports But I'm receiving the error 404 not found as a response to my request.但是我收到错误 404 not found 作为对我请求的响应。 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.我一直在阅读,有时这个 API 停止工作,但我在这里发现https://developer.apple.com/system-status/那,这不可能。

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)首先是令牌生成 function 代码(出于隐私原因我隐藏了一些参数)

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.这是我提出请求的 function。 (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).这个 API 每天在特定时间创建报告,因此如果您请求尚未创建的报告,响应将是错误 404(未找到)。

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 .检查以下链接,解释所有条件https://help.apple.com/app-store-connect/#/dev8a5831138

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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