d
Topic
Posts:
3
April 20, 2010

bad request when creating web hook This post is outdated

Im trying to create a webhook in app after instalation but im getting a Bad Request response...

Im using ruby with Builder and SimpleHttp:

Generating XML:

      xml = Builder::XmlMarkup.new(:indent => 2)

 

      xml.instruct!

      xml.webhook {

        xml.address "my hook address"

        xml.topic "orders/create"

      }

 

Calling API:

 

      http = SimpleHttp.new shopify_api_url + "/admin/webhooks.xml"

      http.basic_authentication self.class.shopify_api_key, shopify_password

      http.post(generate_hook_xml, "text/xml")

 

I also wrote a lot of specs, im sure the password is generating ok with data, and cant understand why its returning bad request (I also tried to use username:password in URL before, also dont worked).

i
Replies
Posts:
3
April 20, 2010

I also dumped data, appears fine...

 

== REQUEST HEADERS

accept=*/*

connection=close

content-type=text/xml

authorization=Basic MY_AUTH

content-length=183

host=MY_HOST

 

===REQUEST BODY

<?xml version="1.0" encoding="UTF-8"?>

<webhook>

  <address>MY HOOK ADDRESS</address>

  <topic>orders/create</topic>

</webhook>

 

 

==RESPONSE HEADERS

connection=close

content-type=text/html

date=Tue, 20 Apr 2010 14:21:37 GMT

server=nginx/0.7.64

content-length=173

 

===RESPONSE BODY

<html>

<head><title>400 Bad Request</title></head>

<body bgcolor="white">

<center><h1>400 Bad Request</h1></center>

<hr><center>nginx/0.7.64</center>

</body>

</html>

anyone have ideias?

Dennis Theisen Shopify
Posts:
46
April 20, 2010

Hey there,

I'm not entirely sure what's wrong with your code, but it seems like the problem is with the way SimpleHTTP (personally never used it before) does Basic Authentication. When I switched to net/http the request worked fine.

See this paste for a completely working example:

http://gist.github.com/372710

 

If you're using just core Ruby you might as well switch Builder for REXML which is included with Ruby so you don't have any external dependencies. See this snippet for a working example on uploading products without any external gem dependencies:

http://gist.github.com/372726

Hope that helps!

 

Cheers, Dennis

Shopify Support Developer

Shopify Support Developer
Posts:
3
April 22, 2010

Thanks Dennis, it worked. I dont know why exactly, but authentication with SimpleHttp as failing. But I still like SimpleHttp, so I modified the library to use core http auth (before it was creating this auth by hand) and all is working fine. I deployed a new gem (since last commit on SimpleHttp was on 2008, its very old) and released on gemcutter, if anyone want, its called fresh_simplehttp and can be found here and source here

Log in or sign up for an account to reply.

This thread has been closed! You will not be able to reply.