POST not allowed at https://www.imified.com/api/bot

Jingsong Wang's Avatar

Jingsong Wang

21 Jun, 2009 01:47 AM via web

I just looked at my response object after POST-ing to the imified API at https://www.imified.com/api/bot, and I got this:

{'status': '405', 'content-length': '1564', 'server': 'Microsoft-IIS/6.0', 'allow': 'OPTIONS, TRACE, GET, HEAD', 'date': 'Sun, 21 Jun 2009 01:42:38 GMT', 'content-type': 'text/html'}

As you can see, in the 'allow' response header, POST isn't allowed. In the API Documentation, it says: All API calls for requesting user details and sending messages should be sent via HTTP POST to the following URL: https://www.imified.com/api/bot/.

Could this be resolved quickly? I've spent many hours trying to figure out what was wrong with my request, only to find that the API isn't functioning as specified...

  1. Support Staff 2 Posted by Adam Kalsey on 21 Jun, 2009 02:13 AM

    Adam Kalsey's Avatar

    It's working fine for me from both Perl and PHP...

    `$ perl poster.pl
    HTTP/1.1 200 OK
    Connection: close
    Date: Sun, 21 Jun 2009 02:10:32 GMT
    Server: Microsoft-IIS/6.0
    Content-Type: application/xml; charset=UTF-8
    Client-Date: Sun, 21 Jun 2009 02:10:32 GMT
    Client-Peer: 208.76.192.166:80
    Client-Response-Num: 1
    Set-Cookie: CFID=24020500;expires=Tue, 14-Jun-2039 02:10:32 GMT;path=/
    Set-Cookie: CFTOKEN=24222736;expires=Tue, 14-Jun-2039 02:10:32 GMT;path=/
    Set-Cookie: CFAUTHORIZATION_imified_api=;expires=Sat, 21-Jun-2008
    02:10:32 GMT;path=/

            <rsp stat="ok">
                    <success msg='sent'/>
            </rsp>`

    I can't figure out why you'd be getting a 405 response.

    Is it possible that your server isn't able to send SSL requests
    (OpenSSL not installed or msiconfigured)? Have you tried sending
    without SSL?

  2. 3 Posted by Jingsong Wang on 21 Jun, 2009 02:31 AM

    Jingsong Wang's Avatar

    This is my httplib2 debug output:

    send: 'POST
    /api/bot?msg=hello&userkey=XXXX-XXXX-XXXX&apimethod=send&botkey=XXXX-XXXX-XXXX
    HTTP/1.1\r\nHost: www.imified.com:443\r\nAccept-Encoding:
    identity\r\nContent-Length: 135\r\nauthorization: Basic
    amluZ3Nvbmd3QGdtYWlsLmNvbTpzdmRrbm4yMg==\r\nuser-agent:
    Python-httplib2/$Rev: 259 $\r\n\r\n'
    send:
    'msg=hello&userkey=XXXX-XXXX-XXXX&apimethod=send&botkey=XXXX-XXXX-XXXX'
    reply: 'HTTP/1.1 405 Method Not Allowed\r\n'
    header: Allow: OPTIONS, TRACE, GET, HEAD
    header: Content-Length: 1564
    header: Content-Type: text/html
    header: Server: Microsoft-IIS/6.0
    header: Date: Sun, 21 Jun 2009 02:26:43 GMT
    {'status': '405', 'content-length': '1564', 'server': 'Microsoft-IIS/6.0',
    'allow': 'OPTIONS, TRACE, GET, HEAD', 'date': 'Sun, 21 Jun 2009 02:26:43
    GMT', 'content-type': 'text/html'}

    I checked that OpenSSL was configured, and that my python was built with SSL
    support. Any users you could refer me to that use Python?

  3. 4 Posted by Jingsong Wang on 21 Jun, 2009 03:43 AM

    Jingsong Wang's Avatar

    After playing with it some more, I discovered that when I POST to /api/bot/ with an extra forward-slash at the end, I get an internal 500 error. In your curl example on the API documentation page, you guys have the URL as:

    $url = 'https://www.imified.com/api/bot/';

    Not sure what to make of it though

  4. 5 Posted by Anthony Webb on 21 Jun, 2009 03:55 AM

    Anthony Webb's Avatar

    Just to be sure, you can hit that url (https://www.imified.com/api/bot/)
    from a browser OK, correct?

  5. 6 Posted by Jingsong Wang on 21 Jun, 2009 04:17 AM

    Jingsong Wang's Avatar

    I'm actually doing it from a server with CentOS 5.3. However, I know it
    works because I ran your php example and it worked perfectly fine.

    So I've finally nailed down what causes what errors.

    If I POST to /api/bot, I get the 405 Method Not Allowed Error.

    If I POST to the /api/bot/ with headers, I get the 500 Internal Server
    Error.

    And if I POST to the /api/bot/ without headers, I'm getting a 200 Status OK
    and :
        <rsp stat="fail">
                <err msg="Your username/password/botkey was not valid!"/>
        </rsp>

    even though I've checked multiple times that my username/pw/botkey are put
    in correctly. Maybe I'm running into some type of python encoding issue...

    I'll play around with it some more.

  6. Support Staff 7 Posted by Adam Kalsey on 21 Jun, 2009 04:49 AM

    Adam Kalsey's Avatar

    I wish I knew more Python to be able to help. Unfortunately, I know
    just enough to be a barely effective copy and paste coder.

  7. Support Staff 8 Posted by Adam Kalsey on 27 Jun, 2009 06:13 AM

    Adam Kalsey's Avatar

    Did you get this figured out?

  8. 9 Posted by Chee-wai on 17 Jul, 2009 04:44 AM

    Chee-wai's Avatar

    I encountered exactly the same problem. Any ideas what is wrong?

  9. Support Staff 10 Posted by Adam Kalsey on 17 Jul, 2009 05:21 PM

    Adam Kalsey's Avatar

    I beleive Jinsong solved his issue, but I'm not sure what the solution was.

  10. 11 Posted by Jingsong on 18 Jul, 2009 09:58 PM

    Jingsong's Avatar

    Yeah, it's a little tricky. I'm going to have to dig up the code. Will
    post later.

  11. 12 Posted by Tom Pierce on 19 Jul, 2009 12:43 PM

    Tom Pierce's Avatar

    I'm also seeing this issue in Python. Tried 3 different methods of connecting - urllib2, httplib, and httplib2. Same symptoms in all 3. 405 if I post to the URL with no slash, 500 if I post to the one with the slash.

  12. 13 Posted by Jingsong Wang on 20 Jul, 2009 06:28 AM

    Jingsong Wang's Avatar

    So here's how to do it.

    First, use urllib2 to generate a request object to
    https://www.imified.com/api/bot/ with the params encoded. Then, take that
    request object and use urllib2's HTTPSHandler() to generate the request, and
    return a response. Now, take that original request object, and add the
    Authorization header to it. Generate a second request with the new request
    object using urllib2.urlopen(). That should complete the handshake.

    This was a huge headache for me, took me almost 2 days to finally get it
    working. Hope this helps.

Comments are currently closed for this discussion. You can start a new one.