responseFields argument allows you to filter which properties are returned or updated by the API, providing you with a more manageable payload to work with and reducing network latency and client SDK parse times.
Use the responseFields argument carefully when retrieving and then modifying a resource, as you can inadvertently delete data. For example, if you use the responseFields argument to retrieve a subset of a resource, make changes to that subset, and then update the resource with the new subset without using the same responseFields argument again, the entire resource may be overwritten with only the subset of data. In general, the responseFields argument is recommended for retrieving select data to display or modify on the storefront, and for selectively updating data. It is not generally recommended for retrieving API resources you intend to modify or process before updating the original object with the changes.
HTTP Request Syntax
To use theresponseFields argument, include it in the GET or PUT HTTP request. For example, the following line shows the placement of the argument for the GetProduct operation request:
GET api/commerce/catalog/admin/products/{productCode}?responseFields={responseFields}
The responseFields argument is optional, and if no value is provided, then the entire resource is retrieved or updated.
Not every PUT operation supports the responseFields argument. Consult the API reference documentation for details on a specific operation.
Basic Example: Include Single Property
The simplest use of theresponseFields argument is to retrieve one specific property.
Example
Argument To Use GETapi/_endpointPath_/?responseFields=a1
API Object
Include Multiple Properties
Similar to the single property example, you can retrieve or update multiple properties at a time by separating them with a comma.Example
Argument To Use GETapi/_endpointPath_/?responseFields=a1,a3
API Object
Exclude Properties
You can exclude one or more properties to retrieve or update by using the negative sign operator.Example
Argument To Use GETapi/_endpointPath_/?responseFields=-a2
API Object
Include and Exclude Properties
You can specify properties to include and exclude within the same argument by combining commas and negative sign operators.Example
Argument To Use GETapi/_endpointPath_/?responseFields=a1,-a3,a4
API Object
Include Wildcards
You can use an asterisk to include properties that are otherwise not explicitly included or excluded in the argument.Example
Argument To Use The following three arguments all return the same payload. GETapi/_endpointPath_/?responseFields=a1,-a2,*
GET api/_endpointPath_/?responseFields=-a2,a3,*
GET api/_endpointPath_/?responseFields=*,-a2
API Object
Arrays
TheresponseField argument works the same for arrays as it does for simple structures. You can include and exclude arrays, as well as use the asterisk symbol to denote wildcards.
Example
Argument To Use GETapi/_endpointPath_/?responseFields=a1,-a3,*
API Object
Include Specific Subresources
The majority of API objects are composed of nested subresources. You can use a forward slash character in theresponseFields argument to include only certain subresources.
Example
Argument To Use GETapi/_endpointPath_/?responseFields=a1/b2
API Object
Include Subresources at any Depth
You can limit inclusion of subresources down to any depth necessary by stringing forward slashes together.Example
Argument To Use GETapi/_endpointPath_/?responseFields=a1/b2/c1
API Object
Exclude Subresources
You can exclude subresources at any depth using the negative sign operator.Example
Argument To Use GETapi/_endpointPath_/?responseFields=a1/b2/-c1
API Object
Include a Subset of Subresources
You can use parentheses to include a subset of subresources. Only the fields between the parentheses are retrieved or updated. Using parentheses instead of forward slashes may be more convenient depending on your use case.Example
Argument To Use GETapi/_endpointPath_/?responseFields=a1(b1,b2(c2))
API Object
Syntax Combinations
TheresponseFields argument lets you combine the syntax operators in the aforementioned sections to achieve powerful and flexible inclusions and exclusions. The following examples in this section demonstrate several example scenarios to give you an idea of how flexible the responseFields argument is:
Combination: Asterisks and Parentheses
Argument To Use GETapi/_endpointPath_/?responseFields=a1(*,b2(c1))
API Object
Combination: Forward Slashes, and Parentheses
Argument To Use GETapi/_endpointPath_/?responseFields=a1/b2(c1,c2)
API Object
Combination: Asterisks, Forward Slashes, and Parentheses
Argument To Use GETapi/_endpointPath_/?responseFields=a1(*,b2/c1)
API Object
Combination: Negation, Asterisks, Forward Slashes, and Parentheses
Argument To Use GETapi/_endpointPath_/?responseFields=a1(*,b2(-c2,-c3))
API Object
Combination: Arrays
Argument To Use GETapi/_endpointPath_/?responseFields=a1(b1/c1,*)
API Object

