One problem I can see straight away is that your deviceId
field is a string, not integer. I would recommend you to compare request with what official web app sends.
I have tried both String and integer but not worked
I have compared all these with official web app parameters and its same still it is giving 400 don't know where the problem is
all other APIs like Geofence Events are working fine but this one causing error
If request is exactly the same, it should obviously work exactly like with the official web app. You must be missing something.
OH, I have found the error
it was in attribute field it was sending "{}" instead of {} i have removed extra quotes and now it is giving me http_code 202 code
and response like this
{"id":0,"attributes":{},"deviceId":84,"type":"engineStop","textChannel":false,"description":"New…"}
It means that it works.
thank you Sir.
I am trying to send command via API using PHP cUrl
I have everything same as web request but still not working and i get http_code =400
Bad request
URL=>
http://my_email:my_password@my_site:8082/api/commands/send
Post Data =>
{ "attributes": "{}", "description": "New...", "deviceId": "84", "id": 0, "textChannel": 0, "type": "engineStop" }
here is my curl code
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,$strPost); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Connection: Keep-Alive' )); $response = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); echo $http_code ; curl_close($ch);