20.09.2023, 17:16
Hi,
I've garbled a script I found, but for some reason my API is refusing the JSON content.
Maybe I've got a typo or I'm just slow..
Here is my current code:
That results in this:
Which I could probably live with as it's just missing some or all values in the JSON format, but I decided to try it through CURL and that works and returns 201 success:
I've tried enclosing "true" and "0" in " but that doesn't make a difference.
Any ideas would be greatly appreciated.
I've garbled a script I found, but for some reason my API is refusing the JSON content.
Maybe I've got a typo or I'm just slow..
Here is my current code:
Code:
require('socket.http')
require('json')
require("ltn12")
body = '{"fault": true,"instID": "string","value": 0,"name": "string"}'
response = {}
start = grp.getvalue('12/4/0')
socket.http.request({
url = "http://192.168.1.69/docs",
method = 'POST',
sink = ltn12.sink.table(response),
headers = {
['accept'] = 'application/json',
['content-type'] = 'application/json',
},
source = ltn12.source.string(body),
})
log(response,headers)
Code:
string: {"detail":[{"type":"missing","loc":["body"],"msg":"Field required","input":null}]}
Which I could probably live with as it's just missing some or all values in the JSON format, but I decided to try it through CURL and that works and returns 201 success:
Code:
curl -X 'POST' \
'http://192.168.1.69/docs' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"fault": true,"instID": "string","value": 0,"name": "string"}'
Any ideas would be greatly appreciated.