英文:
How To Filter Postman API Results
问题
我正在Postman中运行此GET API查询 - https://[myDomain].atlassian.net/wiki/rest/api/space/
,它返回以下结果。
然而,我想要筛选结果,只显示或返回一些特定数据,例如只显示 id
、key
、name
、homepage
和 webui
的值。在Postman中如何实现这一点?
{
"results": [
{
"id": 98430,
"key": "DOC",
"name": "Documents",
"homepage": "/rest/api/content/98633",
"webui": "/spaces/DOC"
},
{
"id": 425986,
"key": "~63be918f98bf50328c68aec2",
"name": "MyDocs",
"homepage": "/rest/api/content/426171",
"webui": "/spaces/~63be918f98bf50328c68aec2"
},
{
"id": 2064386,
"key": "~5f7af04cb61f66006f28fafc",
"name": "Content Management",
"homepage": "/rest/api/content/2064576",
"webui": "/spaces/~5f7af04cb61f66006f28fafc"
},
{
"id": 98306,
"key": "~5f7aef9c8d88b300751faba5",
"name": "AI Development",
"homepage": "/rest/api/content/98389",
"webui": "/spaces/~5f7aef9c8d88b300751faba5"
},
{
"id": 229380,
"key": "SD",
"name": "Software Development",
"homepage": "/rest/api/content/229464",
"webui": "/spaces/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/"
}
}
英文:
I am running this GET API query in Postman - https://[myDomain].atlassian.net/wiki/rest/api/space/
which returns the below results.
However, I'd like to filter out the results to display or return only some specific data, e.g. only the id
, key
, name
, homepage
and webui
values. How can I achieve this in 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/"
}
}
答案1
得分: 2
IMO, 你不能直接筛选结果以在 Postman 响应选项卡中显示。
然而,你可以通过两种解决方法实现你的目标。
- 使用可视化功能:
将以下代码放入你的 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
});
- 使用日志功能:
将以下代码放入你的 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)
})
英文:
IMO, you can't directly filter results to show in postman response tab.
However, you can achieve your goals by 2 work-arounds.
- Use visualization function:
Put this code to your Tests
tab
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
});
- Use logging function:
Put this code to your Tests
tab
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)
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论