2

I'm a C# developer I need to use webhooks to get some stuff after the gethostpage with redirect. Everything it's fine if I use GET ( get events, get my webhooks ), but when I'm going to create a new webhook I get a "The remote server returned an error: (400) Bad Request." for sure it's a stupid thing but I'm stuck.

Any tips?

The request

 byte[] encoded = System.Text.Encoding.Default.GetBytes(apiLogin + ":" + transactionKey);
        string base64 = System.Convert.ToBase64String(encoded);

        var isPost = !string.IsNullOrWhiteSpace(json);

        var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
        httpWebRequest.ContentType = "application/json; charset=utf-8";
        httpWebRequest.Method = isPost ? "POST" : "GET";
        httpWebRequest.Headers.Add("Authorization", "Basic " + base64);
        httpWebRequest.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);


        if (isPost)
        {
            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                streamWriter.Write(json);
                streamWriter.Flush();
            }

        }

        string result = null;

        var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

        using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
        {

            result = streamReader.ReadToEnd();
            return result;
        }


        return result;

I'm trying the JSON sample from documentation sample

John Conde
  • 217,595
  • 99
  • 455
  • 496
  • did you have a look at the actual URL that is sent from you to the server, using Fiddler for example? what URL and headers are expected and which URL and headers are sent by you? – Ronald Rink 'd-fens' Mar 11 '17 at 15:17
  • Found, it is need to create a signature in merchant panel before use "post" webhooks, "get" works also without doing it – Davide Meneghello Mar 12 '17 at 15:34

1 Answers1

2

Found, it is need to create a signature in merchant panel before use "post" webhooks, "get" works also without doing it

  • If you dove deeper into the error message it would have told you that's what you needed to do. I recently encountered the same error and inside the error message was the clue I needed to fix it. – John Conde Mar 15 '17 at 18:12
  • @JohnConde That's not the case, all it said was `INVALID_DATA` and `An error occurred while processing the request. Please note the correlation id for the request and contact Support for more details.`. Thankfully, this answer solved it. – wezten Sep 19 '21 at 15:25