我正在尝试使用此处描述的REST API在datadog中创建一个仪表板:http://docs.datadoghq.com/api/#timeboards
然而,无论我做什么,我都会收到400回复的消息"无效的JSON输入"。我已将json简化为几个必填字段,并清空"图形"部分,但仍然无法运作。
有没有人知道这里可能出现什么问题?
curl -i -X POST 'https://app.datadoghq.com/api/v1/dash?api_key=<key>&application_key=<the_key>' -d '{"dash":{"title":"Foo","description":"bar","graphs":[]}}'
响应
HTTP/1.1 400 Bad Request
Cache-Control: no-cache
Content-Type: application/json
Date: Tue, 31 Jan 2017 18:27:29 GMT
DD-POOL: dogweb_sameorig
Pragma: no-cache
Strict-Transport-Security: max-age=15724800;
X-Content-Type-Options: nosniff
X-DD-VERSION: 34.34544
X-Frame-Options: SAMEORIGIN
Content-Length: 34
Connection: keep-alive
{"errors": ["Invalid JSON input"]}
答案 0 :(得分:1)
您需要将Content-Type
作为请求的标头传递,如图in the docs所示
$ curl -X POST -H "Content-type: application/json" 'https://app.datadoghq.com/api/v1/dash?api_key=<key>&application_key=<key>' -d '{"dash":{"title":"Foo","description":"bar","graphs":[]}}'
响应:
{"errors": ["The parameter 'title' is required"]}
您的数据也没有根据文档格式化(顶级应该没有dash
字段,对于初学者来说。)