title: C# RestClient call to magento api returns 401 signature invalid
body: <p>I am trying to call some specific endpoint on magento from c# RestClient, with no luck. The call starts here :</p>
  
  <pre><code>private void SendDeletedProduct(string itemCode)
      {
          string consumerKey = "....."; 
          string consumerSecret = ".....";
          string tokenSecret = ".....";
          string tokenValue = ".....";
          string url = string.Format("http://.........:8090/api/rest/pylon/{0}", itemCode);
  
          var client = new RestClient(url);
          client.Timeout = -1;
          var request = new RestRequest(Method.PUT);
          request.AddHeader("Content-Type", "application/json");
          request.AddHeader("Authorization", GetHeader("DELETE", consumerKey, consumerSecret, tokenSecret, tokenValue, url));
  
          IRestResponse response = client.Execute(request);
          if (response.StatusCode != HttpStatusCode.OK)
          {
              LogError(response, string.Empty, itemCode, "Product", "DELETE");
          }
      }
  </code></pre>
  
  <p>and the header is generated here :</p>
  
  <pre><code>private string GetHeader(string method, string cKey, string cSecret, string tSecret, string tValue, string apiUrl)
      {
          Dictionary&lt;string, string&gt; oauthD = new Dictionary&lt;string, string&gt;();
          oauthD.Add("consumerKey", cKey);
          oauthD.Add("consumerSecret", cSecret);
          oauthD.Add("tokenSecret", tSecret);
          oauthD.Add("tokenValue", tValue);
          oauthD.Add("url", apiUrl.Replace(":8090", string.Empty));
  
          var timeStamp = ((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString();
          var nonce = Convert.ToBase64String(Encoding.UTF8.GetBytes(timeStamp));
  
          var signatureBaseString = HttpUtility.UrlEncode(method + "&amp;");
          signatureBaseString += HttpUtility.UrlEncode(oauthD["url"] + "&amp;");
          signatureBaseString += HttpUtility.UrlEncode(
                  "oauth_consumer_key=" + oauthD["consumerKey"] + "&amp;" +
                  "oauth_nonce=" + nonce + "&amp;" +
                  "oauth_signature_method=HMAC-SHA1" + "&amp;" +
                  "oauth_timestamp=" + timeStamp + "&amp;" +
                  "oauth_token=" + oauthD["tokenValue"] + "&amp;" +
                  "oauth_version=1.0");
  
          var key = HttpUtility.UrlEncode(oauthD["consumerSecret"] + "&amp;" + oauthD["tokenSecret"]);
  
          var signatureEncoding = new ASCIIEncoding();
          var keyBytes = signatureEncoding.GetBytes(key);
          var signatureBaseBytes = signatureEncoding.GetBytes(signatureBaseString);
          string signatureString;// = HMACSHA1(key, signatureBaseString);
          using (var hmacsha1 = new HMACSHA1(keyBytes))
          {
              var hashBytes = hmacsha1.ComputeHash(signatureBaseBytes);
              signatureString = Convert.ToBase64String(hashBytes);
          }
  
          signatureString = HttpUtility.UrlEncode(signatureString);
  
  
          string SimpleQuote(string s) =&gt; '"' + s + '"';
          string header =             
              "oAuth oauth_consumer_key=" + SimpleQuote(oauthD["consumerKey"]) + "," +
              "oauth_nonce=" + SimpleQuote(nonce) + "," +
              "oauth_signature_method=" + SimpleQuote("HMAC-SHA1") + "," +
              "oauth_timestamp=" + SimpleQuote(timeStamp) + "," +
              "oauth_token=" + SimpleQuote(oauthD["tokenValue"]) + "," +
              "oauth_version=" + SimpleQuote("1.0") + "," +
              "oauth_signature= " + SimpleQuote(signatureString);
  
          return header;
      }
  </code></pre>
  
  <p>Reading around the web and magento docs, i ve found a lot of possible answers but i didnt manage to get the api to respond with 200 ok. I ve tried stripping the port from the url, changing the order of the parameters in the signature string to be alphabetical, tried urlencoding with "&amp;" symbol and leaving "&amp;" outside of urlencode. Calling the api directly from postman works fine btw. So i figure i have something wrong in the way i produce my signature. Any help would be appreciated.</p>
  
  <p>Thanks in advance!</p>