3

I'm calling the IBM Bluemix Administration API for Message Hub (aka Kafka), as described here.

Calling the endpoint https://kafka-admin-prod02.messagehub.services.eu-gb.bluemix.net:443/topics (using an appropriate X-Auth-Token value corresponding to our API key, and a GET verb) seems to work - it returns a list of the topics we've manually configured in the Bluemix Message Hub admin screen.

However, calling the same URL with the verb POST and a body of {name: 'mynewtopicname'} and a Content-Type of application/json (this appears to be the correct syntax, according to the Swagger docs for the API) doesn't work - I get a result of "HTTP 405 Method Not Allowed". That seems to happen whether I use GET, PUT, POST or DELETE (which also means I cannot delete a topic).

Am I doing something wrong?

(I'm using Message Hub on the UK Bluemix instance, if it's relevant).

Andrew Ferrier
  • 16,664
  • 13
  • 47
  • 76

1 Answers1

4

To create topics you need to do a POST to the URL /admin/topics, not /topics. Give it a try and let me know if it works.

Andrew Ferrier
  • 16,664
  • 13
  • 47
  • 76
Luis Elizondo
  • 1,979
  • 2
  • 14
  • 15
  • Luis, thank you! That works. Re-reading the swagger file, I can see that all the admin APIs start `/admin`. Seems like Postman may have autogenerate them wrong when it imported the Swagger file - or I just made a mistake! For the benefit of anyone else reading this, I also had to set the inbound "Content-Type" header to `application/json` - and it seems the JSON parser is *very* fussy, so the field name and value have to be in double-quotes; i.e. `{"name": "mynewtopicname"}`. Now it works! Thanks. – Andrew Ferrier Mar 31 '16 at 19:44
  • 1
    The JSON parser needs double quotes, otherwise is considered invalid. You can use any JSON linter or validator like this one http://jsonlint.com/ to know if your JSON is valid. – Luis Elizondo Mar 31 '16 at 22:06
  • Luis, huh. I just double-checked that and you are right again ;) I've always found single quotes "just worked" in JSON, but I guess I've been using lax parsers. Seems they aren't valid, unlike in JS. You learn something every day :) – Andrew Ferrier Mar 31 '16 at 22:31