You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+47-38Lines changed: 47 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
A standalone API for JS and other clients to use with Schema. Extend basic endpoints with your own custom functionality, for example, validating user input special or scoping product queries for client usage.
4
4
5
5
```
6
-
Schema.io <===> NodeJS API (This Package) <===> Your App (React/Angular/Ember/Rails/Etc)
6
+
Schema.io <==> NodeJS API (This Package) <==> Your App (React/Angular/Ember/Rails/Etc)
7
7
```
8
8
9
9
## Getting Started
@@ -15,10 +15,10 @@ Schema.io <===> NodeJS API (This Package) <===> Your App (React/Angular/Ember/Ra
15
15
16
16
### Example .env file
17
17
18
-
```
18
+
```bash
19
19
NODE_ENV=development
20
20
PORT=3001
21
-
FORCE_SSL=true // if you want to redirect all requests to https
21
+
FORCE_SSL=true # redirect all requests to https
22
22
SCHEMA_CLIENT_ID=my-client-id
23
23
SCHEMA_CLIENT_KEY=my-client-key
24
24
```
@@ -41,43 +41,41 @@ It's not strictly required to pass the session header, but certain endpoints wil
41
41
42
42
#### Get current account (session required)
43
43
44
-
```
44
+
```json
45
45
GET /v1/account
46
46
```
47
47
48
48
Sensitive fields may be removed from the response. See `api/v1/account.js` for details.
@@ -109,7 +107,7 @@ This will send an email to the account if one found, that contains the `reset_ur
109
107
110
108
#### Reset password from recovery email
111
109
112
-
```
110
+
```json
113
111
POST /v1/account/recover
114
112
{
115
113
"reset_key": "iud287ebuf9uwf92fdi2uhef872h",
@@ -123,15 +121,15 @@ This will reset an account's password if the `reset_key` is found. If successful
123
121
124
122
#### Get current cart details (session required)
125
123
126
-
```
124
+
```json
127
125
GET /v1/cart
128
126
```
129
127
130
128
Sensitive fields may be removed from the response. See `api/v1/cart.js` for details.
131
129
132
130
#### Update current cart details
133
131
134
-
```
132
+
```json
135
133
PUT /v1/cart
136
134
{
137
135
"shipping": {
@@ -177,15 +175,15 @@ If the cart does not exist for the current session, it will be automatically cre
177
175
178
176
#### Create cart for the current user
179
177
180
-
```
178
+
```json
181
179
POST /v1/cart
182
180
```
183
181
184
182
This will create a cart for the current session, if one does not already exist. Note that it's not usually necessary to make this request, since other requests like `/v1/cart/add-item` will do the same automatically on demand.
185
183
186
184
#### Add item to cart
187
185
188
-
```
186
+
```json
189
187
POST /v1/cart/add-item
190
188
{
191
189
"product_id": "...",
@@ -205,7 +203,7 @@ If the same product and options already exist in the cart, then its quantity wil
205
203
206
204
#### Remove item from cart
207
205
208
-
```
206
+
```json
209
207
POST /v1/cart/remove-item
210
208
{
211
209
"item_id": "..."
@@ -214,9 +212,22 @@ POST /v1/cart/remove-item
214
212
215
213
This will remove an item from the cart matching `item_id`. You can get the item ID value from any of the previous calls to the cart endpoint.
216
214
217
-
#### Get shipping prices
215
+
#### Apply a coupon
218
216
217
+
```json
218
+
POST /v1/cart/apply-coupon
219
+
{
220
+
"code": "SHIPFREE"
221
+
}
219
222
```
223
+
224
+
This will apply a valid coupon code to the cart and affect all relevant prices. If the coupon code is not found or is not valid, the server will respond with status `400` and an error message.
225
+
226
+
To remove an applied coupon, make the same request with `"code": null`.
227
+
228
+
#### Get shipping prices
229
+
230
+
```json
220
231
GET /v1/cart/shipment-rating
221
232
```
222
233
@@ -226,7 +237,7 @@ The typical flow is to update the cart with shipping information first, then mak
226
237
227
238
### Convert cart to order
228
239
229
-
```
240
+
```json
230
241
POST /v1/cart/checkout
231
242
```
232
243
@@ -238,21 +249,21 @@ If successful, an order record will be returned. Otherwise an error.
238
249
239
250
#### Get category by slug or ID
240
251
241
-
```
252
+
```json
242
253
GET /v1/categories/:slug
243
254
```
244
255
245
256
Sensitive fields may be removed from the response. See `api/v1/categories.js` for details.
246
257
247
258
#### Get sub-categories by slug or ID
248
259
249
-
```
260
+
```json
250
261
GET /v1/categories/:slug/children
251
262
```
252
263
253
264
#### Get products in a category
254
265
255
-
```
266
+
```json
256
267
GET /v1/categories/:slug/products
257
268
```
258
269
@@ -264,15 +275,15 @@ Note: If you want to get products in a single category only and ignore sub-categ
264
275
265
276
#### Get a product
266
277
267
-
```
278
+
```json
268
279
GET /v1/products/:id
269
280
```
270
281
271
282
Sensitive fields may be removed from the response. See `api/v1/products.js` for details.
272
283
273
284
#### Get products in a category
274
285
275
-
```
286
+
```json
276
287
GET /v1/products?category=:slug
277
288
```
278
289
@@ -284,7 +295,7 @@ Note: If you want to get products including all sub-categories, then see `/v1/ca
284
295
285
296
#### Subscribe contact to email list(s)
286
297
287
-
```
298
+
```json
288
299
POST /v1/contacts/subscribe
289
300
{
290
301
"first_name": "Example",
@@ -298,7 +309,7 @@ All fields are optional except `email`. You may use `email_optin_lists` for trac
@@ -313,15 +324,15 @@ This will flip the `email_optin` field to false on the contact record. If `email
313
324
314
325
#### Get a page
315
326
316
-
```
327
+
```json
317
328
GET /v1/pages/:id
318
329
```
319
330
320
331
Pages are used to store content such as About Us, Privacy Policy, etcetera.
321
332
322
333
#### Get page articles
323
334
324
-
```
335
+
```json
325
336
GET /v1/pages/:id/articles
326
337
```
327
338
@@ -330,23 +341,23 @@ Articles are useful for different things depending on the page itself. For examp
330
341
331
342
#### Get a page article
332
343
333
-
```
344
+
```json
334
345
GET /v1/pages/:id/articles/:article_id
335
346
```
336
347
337
348
## /v1/sessions
338
349
339
350
#### Get current session details
340
351
341
-
```
352
+
```json
342
353
GET /v1/session
343
354
```
344
355
345
356
This will return current session data, including `account_id` and `cart_id`, along with any other arbitrary fields stored by your client.
346
357
347
358
#### Update current session details
348
359
349
-
```
360
+
```json
350
361
PUT /v1/session
351
362
{
352
363
"arbitrary_field": "example"
@@ -357,21 +368,19 @@ Update the current session with any fields that might be useful to your client.
357
368
358
369
## Testing
359
370
360
-
To run all tests:
361
-
362
-
```
371
+
```bash
363
372
npm test
364
373
```
365
374
366
-
As a best practice, you should write new tests for new or modified endpoints.
375
+
As a best practice, you should write tests for all new or modified endpoints.
367
376
368
377
#### Schema client testing
369
378
370
379
The test setup includes a Schema client that should be used to stub itself with expected requests and results. This allows you to easily test your own API code, without calling out to the Schema.io API itself. It makes test faster and more reliable.
0 commit comments