@@ -25,18 +25,67 @@ info:
25
25
entity's relations and return them in the response.
26
26
27
27
28
- For example, when you list customers you can also retrieve their groups by
29
- passing to the `expand` query parameter the value `groups`.
28
+ Please note that the relations you pass to `expand` replace any relations
29
+ that are expanded by default in the request.
30
+
31
+
32
+ ### Expanding One Relation
33
+
34
+
35
+ For example, when you retrieve products, you can retrieve their collection
36
+ by passing to the `expand` query parameter the value `collection`:
37
+
38
+
39
+ ```bash
40
+
41
+ curl "http://localhost:9000/admin/products?expand=collection" \
42
+
43
+ -H 'Authorization: Bearer {api_token}'
44
+
45
+ ```
46
+
47
+
48
+ ### Expanding Multiple Relations
30
49
31
50
32
51
You can expand more than one relation by separating the relations in the
33
- `expand` query parameter with a comma. For example, to retrieve both the
34
- orders and the groups of a customer, pass to the `expand` query parameter
35
- the value `groups,orders`.
52
+ `expand` query parameter with a comma.
53
+
54
+
55
+ For example, to retrieve both the variants and the collection of products,
56
+ pass to the `expand` query parameter the value `variants,collection`:
57
+
58
+
59
+ ```bash
60
+
61
+ curl "http://localhost:9000/admin/products?expand=variants,collection" \
62
+
63
+ -H 'Authorization: Bearer {api_token}'
64
+
65
+ ```
66
+
67
+
68
+ ### Prevent Expanding Relations
69
+
70
+
71
+ Some requests expand relations by default. You can prevent that by passing
72
+ an empty expand value to retrieve an entity without any extra relations.
36
73
37
74
38
- Please note that the parameters you pass to `expand` replace any relations
39
- that are expanded by default.
75
+ For example:
76
+
77
+
78
+ ```bash
79
+
80
+ curl "http://localhost:9000/admin/products?expand" \
81
+
82
+ -H 'Authorization: Bearer {api_token}'
83
+
84
+ ```
85
+
86
+
87
+ This would retrieve each product with only its properties, without any
88
+ relations like `collection`.
40
89
41
90
42
91
## Selecting Fields
@@ -47,17 +96,262 @@ info:
47
96
fields in the entity should be returned in the response.
48
97
49
98
99
+ Please note that if you pass a `fields` query parameter, only the fields you
100
+ pass in the value along with the `id` of the entity will be returned in the
101
+ response.
102
+
103
+
104
+ Also, the `fields` query parameter does not affect the expanded relations.
105
+ You'll have to use the `expand` parameter instead.
106
+
107
+
108
+ ### Selecting One Field
109
+
110
+
111
+ For example, when you retrieve a list of products, you can retrieve only the
112
+ titles of the products by passing `title` as a value to the `fields` query
113
+ parameter:
114
+
115
+
116
+ ```bash
117
+
118
+ curl "http://localhost:9000/admin/products?fields=title" \
119
+
120
+ -H 'Authorization: Bearer {api_token}'
121
+
122
+ ```
123
+
124
+
125
+ As mentioned above, the expanded relations such as `variants` will still be
126
+ returned as they're not affected by the `fields` parameter.
127
+
128
+
129
+ You can ensure that only the `title` field is returned by passing an empty
130
+ value to the `expand` query parameter. For example:
131
+
132
+
133
+ ```bash
134
+
135
+ curl "http://localhost:9000/admin/products?fields=title&expand" \
136
+
137
+ -H 'Authorization: Bearer {api_token}'
138
+
139
+ ```
140
+
141
+
142
+ ### Selecting Multiple Fields
143
+
144
+
50
145
You can pass more than one field by seperating the field names in the
51
146
`fields` query parameter with a comma.
52
147
53
148
54
- Only the fields you pass to `field` will be retrieved and returned in the
55
- response. Any fields that are returned by default will not be returned in
56
- this case. This does not affect relations.
149
+ For example, to select the `title` and `handle` of products:
150
+
151
+
152
+ ```bash
153
+
154
+ curl "http://localhost:9000/admin/products?fields=title,handle" \
155
+
156
+ -H 'Authorization: Bearer {api_token}'
157
+
158
+ ```
159
+
160
+
161
+ ### Retrieve Only the ID
162
+
163
+
164
+ You can pass an empty `fields` query parameter to return only the ID of an
165
+ entity. For example:
166
+
167
+
168
+ ```bash
169
+
170
+ curl "http://localhost:9000/admin/products?fields" \
171
+
172
+ -H 'Authorization: Bearer {api_token}'
173
+
174
+ ```
175
+
176
+
177
+ You can also pair with an empty `expand` query parameter to ensure that the
178
+ relations aren't retrieved as well. For example:
179
+
180
+
181
+ ```bash
182
+
183
+ curl "http://localhost:9000/admin/products?fields&expand" \
184
+
185
+ -H 'Authorization: Bearer {api_token}'
186
+
187
+ ```
188
+
189
+
190
+ ## Query Parameter Types
191
+
192
+
193
+ This section covers how to pass some common data types as query parameters.
194
+ This is useful if you're sending requests to the API endpoints and not using
195
+ our JS Client. For example, when using cURL or Postman.
196
+
197
+
198
+ ### Strings
199
+
200
+
201
+ You can pass a string value in the form of `<parameter_name>=<value>`.
202
+
203
+
204
+ For example:
205
+
206
+
207
+ ```bash
57
208
209
+ curl "http://localhost:9000/admin/products?title=Shirt" \
58
210
59
- For example, to only select the `title` and `description` fields of a
60
- product, pass to the `fields` query parameter the value `title,description`.
211
+ -H 'Authorization: Bearer {api_token}'
212
+
213
+ ```
214
+
215
+
216
+ If the string has any characters other than letters and numbers, you must
217
+ encode them.
218
+
219
+
220
+ For example, if the string has spaces, you can encode the space with `+` or
221
+ `%20`:
222
+
223
+
224
+ ```bash
225
+
226
+ curl "http://localhost:9000/admin/products?title=Blue%20Shirt" \
227
+
228
+ -H 'Authorization: Bearer {api_token}'
229
+
230
+ ```
231
+
232
+
233
+ You can use tools like [this one](https://www.urlencoder.org/) to learn how
234
+ a value can be encoded.
235
+
236
+
237
+ ### Integers
238
+
239
+
240
+ You can pass an integer value in the form of `<parameter_name>=<value>`.
241
+
242
+
243
+ For example:
244
+
245
+
246
+ ```bash
247
+
248
+ curl "http://localhost:9000/admin/products?offset=1" \
249
+
250
+ -H 'Authorization: Bearer {api_token}'
251
+
252
+ ```
253
+
254
+
255
+ ### Boolean
256
+
257
+
258
+ You can pass a boolean value in the form of `<parameter_name>=<value>`.
259
+
260
+
261
+ For example:
262
+
263
+
264
+ ```bash
265
+
266
+ curl "http://localhost:9000/admin/products?is_giftcard=true" \
267
+
268
+ -H 'Authorization: Bearer {api_token}'
269
+
270
+ ```
271
+
272
+
273
+ ### Date and DateTime
274
+
275
+
276
+ You can pass a date value in the form `<parameter_name>=<value>`. The date
277
+ must be in the format `YYYY-MM-DD`.
278
+
279
+
280
+ For example:
281
+
282
+
283
+ ```bash
284
+
285
+ curl -g "http://localhost:9000/admin/products?created_at[lt]=2023-02-17" \
286
+
287
+ -H 'Authorization: Bearer {api_token}'
288
+
289
+ ```
290
+
291
+
292
+ You can also pass the time using the format `YYYY-MM-DDTHH:MM:SSZ`. Please
293
+ note that the `T` and `Z` here are fixed.
294
+
295
+
296
+ For example:
297
+
298
+
299
+ ```bash
300
+
301
+ curl -g
302
+ "http://localhost:9000/admin/products?created_at[lt]=2023-02-17T07:22:30Z" \
303
+
304
+ -H 'Authorization: Bearer {api_token}'
305
+
306
+ ```
307
+
308
+
309
+ ### Array
310
+
311
+
312
+ Each array value must be passed as a separate query parameter in the form
313
+ `<parameter_name>[]=<value>`. You can also specify the index of each
314
+ parameter in the brackets `<parameter_name>[0]=<value>`.
315
+
316
+
317
+ For example:
318
+
319
+
320
+ ```bash
321
+
322
+ curl -g
323
+ "http://localhost:9000/admin/products?sales_channel_id[]=sc_01GPGVB42PZ7N3YQEP2WDM7PC7&sales_channel_id[]=sc_234PGVB42PZ7N3YQEP2WDM7PC7"
324
+ \
325
+
326
+ -H 'Authorization: Bearer {api_token}'
327
+
328
+ ```
329
+
330
+
331
+ Note that the `-g` parameter passed to `curl` disables errors being thrown
332
+ for using the brackets. Read more
333
+ [here](https://curl.se/docs/manpage.html#-g).
334
+
335
+
336
+ ### Object
337
+
338
+
339
+ Object parameters must be passed as separate query parameters in the form
340
+ `<parameter_name>[<key>]=<value>`.
341
+
342
+
343
+ For example:
344
+
345
+
346
+ ```bash
347
+
348
+ curl -g
349
+ "http://localhost:9000/admin/products?created_at[lt]=2023-02-17&created_at[gt]=2022-09-17"
350
+ \
351
+
352
+ -H 'Authorization: Bearer {api_token}'
353
+
354
+ ```
61
355
62
356
63
357
## Pagination
@@ -80,16 +374,30 @@ info:
80
374
offset should be 50, and so on.
81
375
82
376
377
+ For example, to limit the number of products returned in the List Products
378
+ endpoint:
379
+
380
+
381
+ ```bash
382
+
383
+ curl "http://localhost:9000/admin/products?limit=5" \
384
+
385
+ -H 'Authorization: Bearer {api_token}'
386
+
387
+ ```
388
+
389
+
83
390
### Response Fields
84
391
85
392
86
- In listing fields, aside from the entities retrieved, there are three
87
- pagination-related fields returned: `count`, `limit`, and `offset`.
393
+ In the response of listing endpoints, aside from the entities retrieved,
394
+ there are three pagination-related fields returned: `count`, `limit`, and
395
+ `offset`.
88
396
89
397
90
- Similarly to the query parameters, `limit` is the maximum number of items
91
- that can be returned in the response, and `field` is the number of items
92
- that were skipped before the entities in the result.
398
+ Similar to the query parameters, `limit` is the maximum number of items that
399
+ can be returned in the response, and `field` is the number of items that
400
+ were skipped before the entities in the result.
93
401
94
402
95
403
`count` is the total number of available items of this entity. It can be
0 commit comments