如何在Postman中筛选API响应里的子JSON对象
Hey there! Sounds like you're trying to narrow down your API results based on nested fields (what you referred to as "sub-objects")—let's break this down step by step using your Convirza API call as an example.
First, let's recap what you've already got working:
- Your current request URL:
GET https://apicfa.convirza.com/v2/call/dni?filter=group_id=8361&limit=10 - It returns a success response with a
dataarray of call objects, each containing fields likecall_id,group_id, anddisposition(which I assume is the nested "sub-object" you want to filter on).
Here's how to filter by nested fields:
Confirm the API's nested filtering syntax
Most REST APIs use one of a few standard patterns to target nested fields:- Dot notation (e.g.,
disposition.statusto target thestatusfield inside thedispositionobject) - Bracket notation (e.g.,
disposition[status]) - Semicolon-separated values if combining multiple filter conditions (e.g.,
group_id=8361;disposition.status=answered)
- Dot notation (e.g.,
Update your filter parameter
Let's say you want to filter calls where thedispositionsub-object has astatusvalue of"answered". Here are a couple of valid URL formats depending on the API's requirements:- If the API supports multiple
filterparameters:GET https://apicfa.convirza.com/v2/call/dni?filter=group_id=8361&filter=disposition.status=answered&limit=10 - If the API expects combined filters in a single
filterparameter:GET https://apicfa.convirza.com/v2/call/dni?filter=group_id=8361;disposition.status=answered&limit=10
Pro tip: If your nested field's value has spaces or special characters, wrap it in quotes, like
disposition.status="call completed".- If the API supports multiple
Test in Postman easily
- Open your request in Postman and navigate to the "Params" tab.
- Add a new key-value pair:
- Key:
filter - Value:
group_id=8361;disposition.status=answered(or the syntax your API requires)
- Key:
- Postman will automatically handle URL encoding for you, so you don't have to manually escape special characters.
- Send the request and check that the
dataarray only includes calls matching your nested field criteria.
Quick troubleshooting tips
- Double-check field names in your API response (case sensitivity is a common gotcha!).
- Some APIs require explicit operators like
AND/OR, e.g.,filter=group_id=8361 AND disposition.status=answered. - If you're stuck, look for filtering examples in the Convirza API docs—they’ll outline the exact syntax for nested objects.
内容的提问来源于stack exchange,提问作者user3708763

