POST not allowed at https://www.imified.com/api/bot
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...
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by Adam Kalsey on 21 Jun, 2009 02:13 AM
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?
3 Posted by Jingsong Wang on 21 Jun, 2009 02:31 AM
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?
4 Posted by Jingsong Wang on 21 Jun, 2009 03:43 AM
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
5 Posted by Anthony Webb on 21 Jun, 2009 03:55 AM
Just to be sure, you can hit that url (https://www.imified.com/api/bot/)
from a browser OK, correct?
6 Posted by Jingsong Wang on 21 Jun, 2009 04:17 AM
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.
Support Staff 7 Posted by Adam Kalsey on 21 Jun, 2009 04:49 AM
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.
Support Staff 8 Posted by Adam Kalsey on 27 Jun, 2009 06:13 AM
Did you get this figured out?
9 Posted by Chee-wai on 17 Jul, 2009 04:44 AM
I encountered exactly the same problem. Any ideas what is wrong?
Support Staff 10 Posted by Adam Kalsey on 17 Jul, 2009 05:21 PM
I beleive Jinsong solved his issue, but I'm not sure what the solution was.
11 Posted by Jingsong on 18 Jul, 2009 09:58 PM
Yeah, it's a little tricky. I'm going to have to dig up the code. Will
post later.
12 Posted by Tom Pierce on 19 Jul, 2009 12:43 PM
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.
13 Posted by Jingsong Wang on 20 Jul, 2009 06:28 AM
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.