cancel
Showing results for 
Search instead for 
Did you mean: 

create new webhooks return bad request

Hi All,

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 stucked.

 

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;

 

and the json that i'm using

 

 

{
  "url": "https://requestb.in/13u2z821",
  "eventTypes": [
    "net.authorize.payment.authcapture.created",
    "net.authorize.customer.created",
    "net.authorize.customer.paymentProfile.created",
    "net.authorize.customer.subscription.expiring"
  ],
  "status": "\"active\"--optional"
}

It's working well for any GET request but i always get "bar request" i tried with webclient also.

 

 

I use requestb.in to test it ( http and https return OK )

 

 

Thank you 

 

 

 

dmeneghello
Member
1 ACCEPTED SOLUTION

Accepted Solutions

Hi @dmeneghello,

 

In your JSON, the last part that says "--optional" shouldn't be there. That was included in our sample code to show that you don't need that line, but it's confusing to show that in the sample. We'll remove it in the next rev of the documentation.

 

Change that last part to

	"status": "active"

and you should be fine.

 

 

View solution in original post

Aaron
All Star
1 REPLY 1

Hi @dmeneghello,

 

In your JSON, the last part that says "--optional" shouldn't be there. That was included in our sample code to show that you don't need that line, but it's confusing to show that in the sample. We'll remove it in the next rev of the documentation.

 

Change that last part to

	"status": "active"

and you should be fine.

 

 

Aaron
All Star