I am getting "Server returned a fault exception: [2] [InvalidKey]Invalid Key" error

I am getting “Server returned a fault exception: [2] [InvalidKey]Invalid Key” error while adding the contact in infusion soft.

invalid key means the access token is either missing or not an access token. Could you be sending the auth token thinking it’s an access token (common mistake)?

This is an error that is thrown when you are trying to use a legacy api key (not OAuth 2.0) that is invalid.

HttpWebRequest request = WebRequest.Create(“https://api.infusionsoft.com/token”) as HttpWebRequest;

        request.Method = "PUT";

        request.Credentials = new NetworkCredential("client_id", "client_secret");

        request.UserAgent = RequestConstants.UserAgentValue;
        request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
        request.KeepAlive = true;
        request.ContentType = "application/x-www-urlencoded";
        var content = string.Empty;

        using (var response = (HttpWebResponse)request.GetResponse())
            using (var stream = response.GetResponseStream())
                using (var sr = new StreamReader(stream))
                    content = sr.ReadToEnd();

Then i am getting “The remote server returned an error: (596) 596”

Please suggest.
or provide me code to get “Access Token” in c#.
I am using class library project in c#.

I’m not a C# guy but I’m pretty sure PUT is not one of the accepted methods for getting access/refresh tokens. Either GET or POST can work.

We still got the same error while we replaced with “PUT” with “POST”.

You have to do more than replace the PUT with POST. POST has specific requirements based on documentation (which it seems I mis-spoke on). You can provide the access token to calls in three ways but requesting authorization to get the access/refresh tokens is only POST.

See the following documentation link for OAuth:


should we have web interface to Request Permission from OAuth , Actually we are using scheduler for infusion soft contact import. So we have limitation to use web interface.
so please suggest.