如何过滤Postman API结果

ppcbkaq5  于 2023-02-19  发布在  Postman
关注(0)|答案(1)|浏览(303)

我在Postman -https://[myDomain].atlassian.net/wiki/rest/api/space/中运行这个GET API查询,它返回以下结果。
但是,我想过滤掉结果,只显示或返回一些特定的数据,例如,只显示idkeynamehomepagewebui值。如何在Postman中实现这一点?

{
    "results": [
        {
            "id": 98430,
            "key": "DOC",
            "name": "Documents",
            "type": "global",
            "status": "current",
            "_expandable": {
                "settings": "/rest/api/space/DOC/settings",
                "metadata": "",
                "operations": "",
                "lookAndFeel": "/rest/api/settings/lookandfeel?spaceKey=DOC",
                "identifiers": "",
                "permissions": "",
                "icon": "",
                "description": "",
                "theme": "/rest/api/space/DOC/theme",
                "history": "",
                "homepage": "/rest/api/content/98633"
            },
            "_links": {
                "webui": "/spaces/DOC",
                "self": "https://xxxxxx.atlassian.net/wiki/rest/api/space/DOC"
            }
        },
        {
            "id": 425986,
            "key": "~63be918f98bf50328c68aec2",
            "name": "MyDocs",
            "type": "personal",
            "status": "current",
            "_expandable": {
                "settings": "/rest/api/space/~63be918f98bf50328c68aec2/settings",
                "metadata": "",
                "operations": "",
                "lookAndFeel": "/rest/api/settings/lookandfeel?spaceKey=~63be918f98bf50328c68aec2",
                "identifiers": "",
                "permissions": "",
                "icon": "",
                "description": "",
                "theme": "/rest/api/space/~63be918f98bf50328c68aec2/theme",
                "history": "",
                "homepage": "/rest/api/content/426171"
            },
            "_links": {
                "webui": "/spaces/~63be918f98bf50328c68aec2",
                "self": "https://xxxxxx.atlassian.net/wiki/rest/api/space/~63be918f98bf50328c68aec2"
            }
        },
        {
            "id": 2064386,
            "key": "~5f7af04cb61f66006f28fafc",
            "name": "Content Management",
            "type": "personal",
            "status": "current",
            "_expandable": {
                "settings": "/rest/api/space/~5f7af04cb61f66006f28fafc/settings",
                "metadata": "",
                "operations": "",
                "lookAndFeel": "/rest/api/settings/lookandfeel?spaceKey=~5f7af04cb61f66006f28fafc",
                "identifiers": "",
                "permissions": "",
                "icon": "",
                "description": "",
                "theme": "/rest/api/space/~5f7af04cb61f66006f28fafc/theme",
                "history": "",
                "homepage": "/rest/api/content/2064576"
            },
            "_links": {
                "webui": "/spaces/~5f7af04cb61f66006f28fafc",
                "self": "https://xxxxxx.atlassian.net/wiki/rest/api/space/~5f7af04cb61f66006f28fafc"
            }
        },
        {
            "id": 98306,
            "key": "~5f7aef9c8d88b300751faba5",
            "name": "AI Development",
            "type": "personal",
            "status": "current",
            "_expandable": {
                "settings": "/rest/api/space/~5f7aef9c8d88b300751faba5/settings",
                "metadata": "",
                "operations": "",
                "lookAndFeel": "/rest/api/settings/lookandfeel?spaceKey=~5f7aef9c8d88b300751faba5",
                "identifiers": "",
                "permissions": "",
                "icon": "",
                "description": "",
                "theme": "/rest/api/space/~5f7aef9c8d88b300751faba5/theme",
                "history": "",
                "homepage": "/rest/api/content/98389"
            },
            "_links": {
                "webui": "/spaces/~5f7aef9c8d88b300751faba5",
                "self": "https://xxxxxx.atlassian.net/wiki/rest/api/space/~5f7aef9c8d88b300751faba5"
            }
        },
        {
            "id": 229380,
            "key": "SD",
            "name": "Software Development",
            "type": "global",
            "status": "current",
            "_expandable": {
                "settings": "/rest/api/space/SD/settings",
                "metadata": "",
                "operations": "",
                "lookAndFeel": "/rest/api/settings/lookandfeel?spaceKey=SD",
                "identifiers": "",
                "permissions": "",
                "icon": "",
                "description": "",
                "theme": "/rest/api/space/SD/theme",
                "history": "",
                "homepage": "/rest/api/content/229464"
            },
            "_links": {
                "webui": "/spaces/SD",
                "self": "https://xxxxxx.atlassian.net/wiki/rest/api/space/SD"
            }
        }
    ],
    "start": 0,
    "limit": 25,
    "size": 5,
    "_links": {
        "base": "https://xxxxxx.atlassian.net/wiki",
        "context": "/wiki",
        "self": "https://xxxxxx.atlassian.net/wiki/rest/api/space/"
    }
}
kuarbcqp

kuarbcqp1#

IMO,你不能直接过滤结果显示在 Postman 响应选项卡.
但是,您可以通过2种变通方法实现您的目标。
1.使用可视化功能:
将此代码放入Tests选项卡

var template = `
    <table bgcolor="#FFFFFF">
        <tr>
            <th>id</th>
            <th>key</th>
            <th>name</th>
            <th>homepage</th>
            <th>webui</th>
        </tr>

        {{#each response}}
            <tr>
                <td>{{id}}</td>
                <td>{{key}}</td>
                <td>{{name}}</td>
                <td>{{_expandable.homepage}}</td>
                <td>{{_links.webui}}</td>
            </tr>
        {{/each}}
    </table>
`;

pm.visualizer.set(template, {
    response: pm.response.json().results
});

1.使用日志记录功能:
将此代码放入Tests选项卡

const res = pm.response.json().results;

res.forEach(e => {
    let x = {
        "id": e.id,
        "key": e.key,
        "name": e.name,
        "homepage": e._expandable.homepage,
        "webuid": e._links.webui
    }
    console.log(x)
})

相关问题