Grafana Jmeter 板无法通过Grafana Delete API从NodeJS代码中删除

oug3syen  于 2023-01-08  发布在  Node.js
关注(0)|答案(1)|浏览(130)

我可以删除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 板仍然在那里。

dw1jzc5e

dw1jzc5e1#

只是调试了更多,看到了一些其他的函数。在代码中将request.get(callOptions, (error, response) => {中的request.get更改为request.delete工作正常,并给出了预期的响应。

相关问题