Search code examples
c#consolerefit

C# console app, refit API Request failed: Response status code does not indicate success: 424 (Failed Dependency)


I have created a net8 console application project and am trying to query using the refit library. I'm using Refit 7.0.0. I don't know why this error occurs. I couldn't find anything about this error on google. I don't understand what kind of erroneous dependency we are talking about.

I am getting the following error:

  API Request failed: Response status code does not indicate success: 424 (Failed Dependency).

Here is all my code:

using Refit;
using System.Text.Json.Serialization;

var request = new SigninRequest
{
    FireBaseToken = "eyJhbGciOiJSUzI1NiIsImtpZCI6IjE2OTgxNjE0MDEwOTYxNjU5g1MTMxMTM1MzAzODU1NDUyNzU2NjciLCJ0eXAiOiJKV1QCJhbGciOiJSUzI1NiIsImtpZCI6IjE2OTgxNNjU5ODg1MTMxMTM1MzAzODU1NDUyNzU",
    Password = "Password",
    Email = "[email protected]",
    AppVersion = 21
};


try
{
    var value =  await RestService.For<ISignin>("https://api.smartex.kg/courier").SigninAsync(request).ConfigureAwait(false);
}
catch (Exception ex)
{

    Console.WriteLine($"API Request failed: {ex.Message}");
    Console.WriteLine($"HTTP Status Code: {ex.StackTrace}");
}


public interface ISignin
{
    [Post("/login")]
    public Task<Response> SigninAsync([Body]SigninRequest request);
}

public class Response
{
    [JsonPropertyName("type")]
    public int Type { get; set; }

    [JsonPropertyName("error")]
    public string? Error { get; set; }
}

public class SigninRequest
{
    [JsonPropertyName("email")]
    public string Email { get; set; } = "";

    [JsonPropertyName("fireBaseToken")]
    public string FireBaseToken { get; set; } = "";

    [JsonPropertyName("appVersion")]
    public int AppVersion { get; set; } = 21;

    [JsonPropertyName("password")]
    public string Password { get; set; } = "";
}

Solution

  • My problem was that I didn't add a Header attribute to the method.

    public interface ISignin
    {
        [Post("/login")]
        [Headers("Content-Type: application/json")]
        public Task<Response> SigninAsync([Body] SigninRequest request);
    }