Bad request -"Error: With 'username' set, you also need to specify 'apiKey'"

Here is my C# code, which looks fine IMHO:

    public static string SpellCheckWithLanguageDotOrg(string textToCheck)
    {
        RestClient SpellCheck_Client = new RestClient("https://api.languagetoolplus.com/v2/check");
        RestRequest postRequest = new RestRequest(Method.POST);

        //curl -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json'
            //-d 'text=I%20aam%20Mr.%20Bootiful%20and%20wery%20respektfoul
                //&language=en-US
                //&username=yyyyyyyyyyy
                //&apiKey=xxxxxxxxxxxxxxx
                //&motherTongue=de-DE
                //&enabledOnly=false
                //&level=picky' 'https://api.languagetoolplus.com/v2/check'

        postRequest.Parameters.Clear();
        postRequest.AddHeader("Content-Type", "application/x-www-form-urlencoded");
        postRequest.AddHeader("Accept", "application/json");            

        postRequest.AddParameter("text", textToCheck);
        postRequest.AddParameter("language", "en-US");
        postRequest.AddParameter("username", "CORRECT__USERNAME__FROM__PAGE");
        postRequest.AddParameter("apikey", "CORRECT__KEY__FROM__PAGE");
        postRequest.AddParameter("motherTongue", textToCheck);
        postRequest.AddParameter("enabledOnly", "false");
        postRequest.AddParameter("level", "picky");
        postRequest.RequestFormat = DataFormat.Json;

        var response = SpellCheck_Client.Execute(postRequest);
        var content = response.Content;
        return content;
    }

Can some1 maybe tell me what am I doing wrong:

Lamguage: C# 8.0
RestApi: RestSharp (Nuget Packge via Visual Studio 2019)

Best regards

Shpendicus

Use apiKey, not apikey as the parameter name.

1 Like