Sadaf Shafi
Sadaf Shafi

Reputation: 1458

Why do I get error ("status":405,"error":"Method Not Allowed") upon sending data to Thingsboard device via command line

I was just sending some data to my device in thingsboard by writing this command on command line

curl -v -X POST -d "{\"temperature\": 25}" http://demo.thingsboard.io/devices/api/v1/IG4XXXXXXXXXCQM/telemetry
--header "Content-Type:application/json"

but I get this error message at the last

{"timestamp":"2020-01-16T13:09:05.031+0000","status":405,"error":"Method Not Allowed","message":"Request method 'POST' not supported","path":"/devices/api/v1/IG4Dxxxxxxxxxxxxxxxxs6CCQM/telemetry"}* Connection #0 to host demo.thingsboard.io left intact

what's it I am not doing right? All the efforts are appreciated Following are the documentation and whole error message

Thingsboard

Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 104.196.24.70:80...
* TCP_NODELAY set
* Connected to demo.thingsboard.io (104.196.24.70) port 80 (#0)
> POST /devices/api/v1/IGxxxxxxxs6CCQM/telemetry HTTP/1.1
> Host: demo.thingsboard.io
> User-Agent: curl/7.65.1
> Accept: */*
> Content-Type:application/json
> Content-Length: 19
>
* upload completely sent off: 19 out of 19 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 405
< Allow: GET, HEAD
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< Content-Type: application/json;charset=UTF-8
< Content-Language: en
< Transfer-Encoding: chunked
< Date: Thu, 16 Jan 2020 13:09:04 GMT
<
{"timestamp":"2020-01-16T13:09:05.031+0000","status":405,"error":"Method Not Allowed","message":"Request method 'POST' not supported","path":"/devices/api/v1/IGxxxxxxxxxxxs6CCQM/telemetry"}* Connection #0 to host demo.thingsboard.io left intact

Upvotes: 4

Views: 1733

Answers (2)

Winfred
Winfred

Reputation: 41

I have a similar problem. I am running

curl POST http://0.0.0.0:5000/api/v1/states/ -H "Content-Type: application/json" -d '{"name": "Nairobi"}' -vvv

my error is this

Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 0.0.0.0:5000...
* TCP_NODELAY set
* Connected to 0.0.0.0 (127.0.0.1) port 5000 (#0)
> POST /api/v1/states/ HTTP/1.1
> Host: 0.0.0.0:5000
> User-Agent: curl/7.68.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 19
>
* upload completely sent off: 19 out of 19 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 405 METHOD NOT ALLOWED
< Server: Werkzeug/2.3.4 Python/3.8.10
< Date: Tue, 30 May 2023 08:54:51 GMT
< Content-Type: text/html; charset=utf-8
< Allow: HEAD, GET, OPTIONS
< Content-Length: 153
< Connection: close
<
<!doctype html>
<html lang=en>
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>
* Closing connection 0

The command I am running is given by my school and is used to check my objects. I can't do anything about it. My create method looks like this:

@app_views.route('/states', methods=['POST'])
  def create_state(state):
      """ Create a state """
      data = request.get_json()
      if data is None:
          abort(400, "Not a JSON")
      name = data["name"]
      if not name:
         abort(400, "Missing name")
      state = State(name=name)
      state_dict = state.to_dict()
      storage.new(state)
      storage.save()
      return jsonify(state_dict), 201

Upvotes: 0

finickyTunnel
finickyTunnel

Reputation: 148

You need to replace 'device' with 'api' in your URL,in case you are using access tokens, hence, instead of

curl -v -X POST -d "{\"temperature\": 25}" http://demo.thingsboard.io/devices/api/v1/IG4XXXXXXXXXCQM/telemetry
--header "Content-Type:application/json"

You need to use

curl -v -X POST -d "{\"temperature\": 25}" http://demo.thingsboard.io/api/v1/IG4XXXXXXXXXCQM/telemetry
--header "Content-Type:application/json"

Upvotes: 2

Related Questions