Search code examples
restibm-cloudiot

Error 400 using REST APIs to IBM Watson IoT platform


I'm attempting to transmit a json formatted message using the REST APIs from an embedded system to the IBM Watson IoT Platform. I've tested the REST APIs using another program (postman) and it works fine however an identical string transmitted from my embedded system returns an error 400. Is there so "extra" security certificate I need in my embedded system to make this work? Or is there something else I am missing?

Here's a link to the REST API for messaging: https://docs.internetofthings.ibmcloud.com/apis/swagger/v0002/http-messaging.html

The following is the string output from my embedded system (via socket connection) where typeID, deviceID, eventName, and orgID are correctly entered and encode64(name token) is the correct authorization string of the concatenation of the name and token encoded in base64.

POST /api/v0002/device/types/typeID/devices/deviceID/events/eventName HTTP/1.1
Host: orgID.messaging.internetofthings.ibmcloud.com:80
Content-Type: application/json
Authorization: Basic encode64(name token)

{random JSON formatted message}

The socket connection is made by first resolving the IP address of the following URI: orgID.messaging.internetofthings.ibmcloud.com then employing standard socket connection function to the IP address and port 80.

While the IoT Platorm API make no mention of using port 80, I can transmit my JSON formatted message to my IoT Platform using port 80 through Postman.


Solution

  • I resolved my issue. My ordering of the carriage return and new line characters was incorrect for the HTTP specification. That is: "\r\n" instead of "\n\r". Everything is working now.