使用 REST 创建数据狗仪表板 API
Creating a datadog dashboard using REST API
我正在尝试使用此处描述的 REST API 在 datadog 中创建仪表板:http://docs.datadoghq.com/api/#timeboards
然而,无论我做什么,我都会收到 400 响应并返回一条消息 "Invalid JSON input"。我已将我的 json 简化为仅几个必填字段和空的 "graphs" 部分,但仍然不起作用。
有没有人知道这里可能出了什么问题?
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"]}
您需要将 Content-Type
作为 header 与请求一起传递,如图 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
字段)。