401.0000007 Error while trying to get the DHL Interface C# code. Followed DHL document

165 views Asked by At

I have been trying to connect to DHL interface but i cannot get the token access key from C# code. here is my current code. Please let me know if you have a solution -

 RestClient client = new RestClient();
            client.ClearHandlers();
            client.Timeout = -1;
            client.BaseUrl = new Uri("https://api-sandbox.dhlecs.com/auth/v4/accesstoken");
            client.Authenticator = new HttpBasicAuthenticator(ConfigurationManager.AppSettings["DHLClientId"], ConfigurationManager.AppSettings["DHLClientSecret"]);
        var request = new RestRequest(Method.POST);
        request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
        request.AddHeader("Accept", "application/json");
        request.Parameters.Clear();
        request.AddParameter("grant_type", "client_credentials");
        IRestResponse response = client.Execute(request);
        var local = response.Content.ToString();

        if (response.StatusCode == HttpStatusCode.OK)
        {
            return response.Content.ToString();
        }
        else
        {
            throw new Exception($@"Unable to authorize with GLS. Contact IT");
        }

here is the error i get -

https://api-sandbox.dhlecs.com/docs/errors/401.0000007"

>> Solution : this needs to be removed -

    request.Parameters.Clear();
0

There are 0 answers