我可以删除Grafana Jmeter 板通过其删除API从 Postman ,但当我尝试删除它通过NodeJS代码,它是不工作的。我得到的状态为200从代码,但我得到的响应体是不同的 Postman 之一。
我正在使用grafana的此删除API- grafana_host_url/api/ Jmeter 板/uid/:uid
我的代码函数是这样的
function deleteGrafana(req) {
return new Promise((resolve, reject) => {
console.log("Inside Delete Grafana")
var dashbord_api_url = req.grafana_host_url + process.env.GRAFANA_DASHBOARD_DELETE_API_URL + req.uid
var api_token = "Bearer " + req.grafana_api_key
console.log("URL:",dashbord_api_url)
console.log("api token:",api_token)
var callOptions = {
'method': 'DELETE',
'url': dashbord_api_url,
'headers': {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': api_token
}
};
request.get(callOptions, (error, response) => {
if (error) {
throw new Error(error)
}
console.log("deleteGrafana Response" + response.body);
var result = {};
result.status = response.statusCode
console.log("Result Status code:",result.status)
resolve(result)
});
});
}
当我运行它时,我的React是这样的-
deleteGrafana Response{"meta":{"type":"db","canSave":true,"canEdit":true,"canAdmin":true,"canStar":true,"canDelete":true,"slug":"sampletest","url":"/d/najkl-oo/sampletest","expires":"0001-01-01T00:00:00Z","created":"2022-12-29T11:43:00Z","updated":"2022-12-29T11:43:01Z","updatedBy":"Anonymous","createdBy":"Anonymous","version":2,"hasAcl":false,"isFolder":false,"folderId":0,"folderUid":"","folderTitle":"General","folderUrl":"","provisioned":false,"provisionedExternalId":"","annotationsPermissions":{"dashboard":{"canAdd".....
理想的响应应该与此API的实际grafana响应相同,如下所示-
{
"id": xx,
"message": "Dashboard deleted",
"title": "sample test"}
我该怎么做才能解决这个问题,让我的删除功能正常工作?当我检查grafana示例并浏览文件夹时, Jmeter 板仍然在那里。
1条答案
按热度按时间dw1jzc5e1#
只是调试了更多,看到了一些其他的函数。在代码中将
request.get(callOptions, (error, response) => {
中的request.get
更改为request.delete
工作正常,并给出了预期的响应。