vernu/textbee

use with curl

wanbalan opened this issue · 1 comments

curl -X POST -d @data.txt 'https://api.textbee.dev/api/v1/gateway/devices/$DEVICEID/sendSMS'
Content data.txt:
{
recipients: [ '+123556789' ], message: 'Hello World!', }, { headers: {
'x-api-key': myapi,
},
}

{"error":"Unauthorized"}
messages are sent successfully from the dashboard with the same data

curl -vv -X POST -H "Content-Type: application/json" -d @data.txt 'https://api.textbee.dev/api/v1/gateway/devices/$DEVICEID/sendSMS'
Note: Unnecessary use of -X or --request, POST is already inferred. * Trying 75.119.150.119:443... * Connected to api.textbee.dev (75.119.150.119) port 443

  • ALPN: curl offers h2,http/1.1 * TLSv1.3 (OUT), TLS handshake, Client hello (1):
  • CAfile: /etc/ssl/certs/ca-certificates.crt * CApath: /etc/ssl/certs
  • TLSv1.3 (IN), TLS handshake, Server hello (2): * TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
  • TLSv1.3 (IN), TLS handshake, Certificate (11): * TLSv1.3 (IN), TLS handshake, CERT verify (15):
  • TLSv1.3 (IN), TLS handshake, Finished (20): * TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
  • TLSv1.3 (OUT), TLS handshake, Finished (20): * SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
  • ALPN: server accepted h2 * Server certificate:
  • subject: CN=api.textbee.dev * start date: May 10 04:06:52 2024 GMT
  • expire date: Aug 8 04:06:51 2024 GMT * subjectAltName: host "api.textbee.dev" matched cert's "api.textbee.dev"
  • issuer: C=US; O=Let's Encrypt; CN=R3 * SSL certificate verify ok.
  • TLSv1.3 (IN), TLS handshake, Newsession Ticket (4): * using HTTP/2
  • [HTTP/2] [1] OPENED stream for https://api.textbee.dev/api/v1/gateway/devices/(mydevid)/sendSMS
  • [HTTP/2] [1] [:method: POST] * [HTTP/2] [1] [:scheme: https]
  • [HTTP/2] [1] [:authority: api.textbee.dev] * [HTTP/2] [1] [:path: /api/v1/gateway/devices/(mydevid)/sendSMS]
  • [HTTP/2] [1] [user-agent: curl/8.4.0] * [HTTP/2] [1] [accept: /]
  • [HTTP/2] [1] [content-type: application/json] * [HTTP/2] [1] [content-length: 135]

POST /api/v1/gateway/devices/(mydevid)/sendSMS HTTP/2 > Host: api.textbee.dev
User-Agent: curl/8.4.0 > Accept: /
Content-Type: application/json > Content-Length: 135 > < HTTP/2 400
< access-control-allow-origin: * < alt-svc: h3=":443"; ma=2592000
< content-type: application/json; charset=utf-8 < date: Mon, 20 May 2024 14:14:33 GMT
< etag: W/"5d-ZwJAYbzEpIU89cV71XRzfZrRRao" < server: Caddy
< x-powered-by: Express < content-length: 93
< * Connection #0 to host api.textbee.dev left intact
{"statusCode":400,"message":"Unexpected token r in JSON at position 3","error":"Bad Request"}

looks like you're sending the headers inside the body, that's why you're getting this error.
please update your request and try again, it should be something like this

curl -X POST \ https://api.textbee.dev/api/v1/gateway/devices/${DEVICE_ID}/sendSMS \ -H 'x-api-key: ${API_KEY}' \ -H 'Content-Type: application/json' \ -d '{ "recipients": ["+123556789"], "message": "Hello World!" }'