JWT for App Store Server API requests

Hello, I'm trying to generate a JWT in C# for calling this endpoint -> https://developer.apple.com/documentation/appstoreserverapi/look_up_order_id

I have followed the instructions in the documentation, but I'm always getting "Unauthenticated" as a response.

The private key used is of type "In-App Purchase" as the documentation says.

Here you have a response with a Request ID:

Unauthenticated

Request ID: YGV3ELXFCFHA5IPRZEW76S66NQ.0.0

This is the code used to generate the JWT:

public string CreateNewApiToken()
    {
        const string audience = "appstoreconnect-v1";

        var kid = "***";
        var privateKey = "***";
        var bundleId = "***";
        var issuerId = "***";
        var now = DateTime.UtcNow;

        using var ecdsa = ECDsa.Create();
        ecdsa?.ImportPkcs8PrivateKey(Convert.FromBase64String(privateKey), out _);

        var signingCredentials = new SigningCredentials(new ECDsaSecurityKey(ecdsa), SecurityAlgorithms.EcdsaSha256);
        signingCredentials.Key.KeyId = kid;

        var payload = new JObject
        {
            { "iss", issuerId },
            { "iat", now.ToUnixTime() },
            { "exp", now.AddMinutes(30).ToUnixTime() },
            { "aud", audience },
            { "bid", bundleId}
        };

        var handler = new JsonWebTokenHandler();
        var token = handler.CreateToken(payload.ToJson(), signingCredentials);
        return token;
    }

Thanks in advance.

Could you please double check your kid matches the key id from App Store Connect? If that does not improve things, please file a ticket in Feedback Assistant and we can take a closer look (http://feedbackassistant.apple.com)

My private key is in the format AuthKey_keyId.p8 and this line ecdsa?.ImportPkcs8PrivateKey(Convert.FromBase64String(privateKey), out _); throws => Unhandled exception. System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. at System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength) at System.Convert.FromBase64String(String s) Any ideas?

JWT for App Store Server API requests
 
 
Q