Fields and expand query parameters
Learn how to use field and expand query parameters.
Most of the Shoppers resources support query parameters. When you add parameters to a request, you modify the results in the response to changing the resource representation, refining your query, and paginating the results. Some query parameters modify the resource by changing the locale or pricing information. The API returns a default set of fields for each resource you request. You can override the default fields returned by using the fields
and expand
query parameters when the default fields do not meet your specific needs.
Fields query parameter
Use the fields
query parameter to filter the fields that appear in a response to just the fields you specifically request. Filtering the fields returned in the response can conserve bandwidth and accelerate response time.
The following response gets the fields available by default for an authenticated customer. Line numbers 8
to 21
display links that are only available for an authenticated customer.
The next example gets the same customer's first and last name only. Notice that the response only includes the fields you specified.
Expand query parameter
Use the expand
query parameter when you need additional information. The expand
query parameter increases the set of fields that appear in the response in addition to the default fields. Expanding resources reduces the number of API calls required to accomplish a task.
The following example gets the same customer and requests specific resource fields: locale
and currency. Line numbers 8
and 9
show the locale
and currency
for the customer in the response.
The next example gets the same customer and requests all the fields with expand=all
.
Tip: Avoid using the expand=all
parameter if you want to reduce the information returned and ensure optimal performance.
As you can see in this example, more fields are available with full resource expansion. Notice that an authenticated customer session also provides links (non-expandable) to orders and subscriptions. You can expand addresses and payment options; however, you must make follow-up calls for orders and subscriptions.
Parameter precedence
The expand
parameter with a value of all
overrides the fields
parameter when both are specified within a URL. For example, the results for GET v1/shoppers/me?fields=firstName&expand=all
returns all fields for a customer.
Last updated