Backend API

A return is an action normally requested by a customer to return products purchased from a store. They contain information about returning items that were previously fulfilled, the return shipment details if applicable, and return value to apply to an order, which in turn may prompt an administrator to issue a refund.

Fields

id

objectId

Unique identifier for the return.

order_id

objectIdrequired

ID of the order this return was created for.

canceled

boolean

Indicates the return was canceled.

carrier

string

ID of a third-party carrier offering the service, if applicable.

carrier_name

string

Name of a third-party carrier offering the service, if applicable.

credit_tax

currencyauto

Total amount of taxes credited to the order for the returned items.

credit_total

currencyauto

Total amount of additional credit applied to the order.

currency

stringrequired

Three-letter ISO currency code in uppercase. Defaults to the store's base currency.

date_created

dateauto

Date and time the return was created.

date_estimated

date

Date the expected return shipment is meant to arrive at a warehouse, if applicable.

date_updated

dateauto

Date and time the return was last updated.

destination

object

The intended return destination.

extra_credit

currencyrequired

Arbitrary amount to apply to the order as compensation for their inconvenience.

item_quantity_receivable

intauto

Total quantity of line items that can still be received in a return shipment.

item_quantity_received

intauto

Total quantity of line items that have been received in a return shipment.

item_quantity_restockable

intauto

Total quantity of line items that can still be restocked to product inventory.

item_quantity_restocked

intauto

Total quantity of line items that have been restocked to product inventory.

notes

string

Internal admin notes, not visible to the customer.

notifications

Notification

Expandable list of notifications sent on behalf of the products returned.

number

stringauto

Unique incremental return number, assigned automatically.

order

Order

Expandable link to the order.

origin

object

The customer's location of origin for the return shipment.

reason_code

string

Code indicating the reason for the return.

received

booleanauto

Indicates that all items have been received in a return shipment.

restock_fee

currency

Amount to charge the customer for re-stocking the returned items.

service

string

ID of a shipping service as configured in shipment settings.

service_name

string

Name of the return shipping service.

shipment_tax

currencyauto

Amount to apply to the order as a credit as compensation for the original shipping tax.

shipment_total

currency

Amount to apply to the order as a credit as compensation for the original shipping price.

tracking_code

string

Tracking code used to identify the return shipment, if applicable.

The return model
{
  "id": "60f199509111e70000000078",
  "items": [
    {
      "id": "5ca537326a0ec32a521139dd",
      "order_item_id": "5a9ea7ba3f95740a914267f2",
      "product_id": "5cad15bc9b14d1990724663b",
      "quantity": 2,
      "quantity_received": 0,
      "quantity_receivable": 2,
      "quantity_restocked": 0,
      "quantity_restockable": 2
    }
  ],
  "order_id": "60f199509111e7000000007a",
  "currency": "USD",
  "date_created": "2021-07-16T14:36:00.399Z",
  "date_updated": "2021-07-16T14:36:00.399Z",
  "origin": {
    "name": "Jon Snow",
    "address1": "1 Main Street",
    "city": "Brooklyn",
    "state": "NY",
    "zip": 11201,
    "country": "US",
    "phone": "(555) 555-5555"
  },
  "received": false,
  "service": "fedex_ground",
  "tracking_code": "T192000000XYZ"
}

Create a new return. If you wish to generate your own unique ID for the record, it must use BSON ObjectID format for compatibility.

Arguments

items

array of objectrequired

List of line items describing the products returned.

order_id

objectIdrequired

ID of the order this return was created for.

notes

string

Internal admin notes, not visible to the customer.

POST/returns
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.post('/returns', {
  order_id: '5a9ea7ba3f95740a914267f1',
  items: [
    {
      order_item_id: '5a9ea7ba3f95740a914267f2',
      product_id: '5cad15bc9b14d1990724663a',
      quantity: 2,
    }
  ],
  notes: 'Damaged in transit',
});
Response
{
  "id": "5cad15bc9b14d1990724663a",
  "number": "R10001",
  "order_id": "5a9ea7ba3f95740a914267f1",
  "items": [
    {
      "id": "5a9ea7ba3f95740a914267f2",
      "order_item_id": "5a9ea7ba3f95740a914267f2",
      "product_id": "5cad15bc9b14d1990724663b",
      "quantity": 2,
      "quantity_received": 0,
      "quantity_receivable": 2,
      "quantity_restocked": 0,
      "quantity_restockable": 2,
      ...
    }
  ],
  "item_quantity_received": 0,
  "item_quantity_receivable": 2,
  "item_quantity_restocked": 0,
  "item_quantity_restockable": 2,
  "shipment_total": 0,
  "shipment_tax": 0,
  "extra_credit": 10,
  "restock_fee": 0,
  "credit_total": 10,
  "credit_tax": 0,
  "notes": "Damaged in transit",
  ...
}

Retrieve a return with the Swell Backend API.

Arguments

id

objectIdrequired

The id of the refund to retrieve.

GET/returns/:id
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.get('/returns/{id}', {
});
The return model
{
  "id": "60f199509111e70000000083",
  "items": [
    {
      "id": "5ca537326a0ec32a521139dd",
      "order_item_id": "5a9ea7ba3f95740a914267f2",
      "product_id": "5cad15bc9b14d1990724663b",
      "quantity": 2,
      "quantity_received": 0,
      "quantity_receivable": 2,
      "quantity_restocked": 0,
      "quantity_restockable": 2
    }
  ],
  "order_id": "60f199509111e70000000084",
  "currency": "USD",
  "date_created": "2021-07-16T14:36:00.399Z",
  "date_updated": "2021-07-16T14:36:00.399Z",
  "origin": {
    "name": "Jon Snow",
    "address1": "1 Main Street",
    "city": "Brooklyn",
    "state": "NY",
    "zip": 11201,
    "country": "US",
    "phone": "(555) 555-5555"
  },
  "received": false,
  "service": "fedex_ground",
  "tracking_code": "T192000000XYZ"
}

Update an existing return using the ID that was obtained when it was created.

Arguments

id

objectIdrequired

Unique identifier for the return.

order_id

objectIdrequired

ID of the order this return was created for.

service

string

ID of a shipping service as configured in shipment settings.

tracking_code

string

Tracking code used to identify the return shipment, if applicable.

PUT/returns/:id
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.put('/returns/{id}', {
  id: '60f199509111e70000000078',
  tracking_code: 'T192000000XYZ',
  service: 'fedex_ground'
});
Response
{
  "id": "60f199509111e70000000078",
  "items": [
    {
      "id": "5ca537326a0ec32a521139dd",
      "order_item_id": "5a9ea7ba3f95740a914267f2",
      "product_id": "5cad15bc9b14d1990724663b",
      "quantity": 2,
      "quantity_received": 0,
      "quantity_receivable": 2,
      "quantity_restocked": 0,
      "quantity_restockable": 2
    }
  ],
  "order_id": "60f199509111e7000000007d",
  "currency": "USD",
  "date_created": "2021-07-16T14:36:00.399Z",
  "date_updated": "2021-07-16T14:36:00.399Z",
  "origin": {
    "name": "Jon Snow",
    "address1": "1 Main Street",
    "city": "Brooklyn",
    "state": "NY",
    "zip": 11201,
    "country": "US",
    "phone": "(555) 555-5555"
  },
  "received": false,
  "service": "fedex_ground",
  "tracking_code": "T192000000XYZ"
}

Return a list of... returns.

Arguments

expand

string

Expand link fields and child collections by using the expand argument.

  • For example, expand=account would return a related customer account if one exists.

When the field represents a collection, you can specify the query limit.

  • For example, expand=variants:10 would return up to 10 records of the variants collection.

See expanding for more details.

fields

string

Returns only the specified fields in the result.

  • For example fields=name,slug would return only the fields name and slug in the response.

Supports nested object and array fields using dot-notation.

  • For example, items.product_id. The product id is always returned.

include

object

Include one or more arbitrary queries in the response which are potentially related to the main query.

See including for more details.

limit

int

Limit the number of records returned, ranging between 1 and 1000. Defaults to 15.

page

int

The page number of results to return given the specified or default limit.

search

string

A text search is performed using the search argument. Searchable fields are defined by the model.

  • For example, search=red would return records containing the word "red" anywhere in the defined text fields.

See searching for more details.

sort

string

Expression to sort results by using a format similar to a SQL sort statement.

  • For example, sort=name asc would return records sorted by name ascending.

See sorting for more details.

where

object

An object with criteria to filter the result.

  • For example, active=true would return records containing a field active with the value true.

It's also possible to use query operators, for example, $eq, $ne, $gt, and more.

See querying for more details.

GET/returns
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.get('/returns/{id}', {
  id: '60f199509111e7000000007f'
});
Response
{
  "count": 51,
  "results": [
    {
      "id": "60f199509111e70000000078",
      "items": [
        {
          "id": "5ca537326a0ec32a521139dd",
          "order_item_id": "5a9ea7ba3f95740a914267f2",
          "product_id": "5cad15bc9b14d1990724663b",
          "quantity": 2,
          "quantity_received": 0,
          "quantity_receivable": 2,
          "quantity_restocked": 0,
          "quantity_restockable": 2
        }
      ],
      "order_id": "60f199509111e70000000088",
      "currency": "USD",
      "date_created": "2021-07-16T14:36:00.399Z",
      "date_updated": "2021-07-16T14:36:00.399Z",
      "origin": {
        "name": "Jon Snow",
        "address1": "1 Main Street",
        "city": "Brooklyn",
        "state": "NY",
        "zip": 11201,
        "country": "US",
        "phone": "(555) 555-5555"
      },
      "received": false,
      "service": "fedex_ground",
      "tracking_code": "T192000000XYZ"
    },
    {...},
    {...}
  ],
  "page": 1,
  "pages": {
    "1": {
      "start": 1,
      "end": 25
    },
    "2": {
      "start": 26,
      "end": 50
    },
    "2": {
      "start": 51,
      "end": 51
    }
  }
}

Delete an existing Return.

Arguments

id

objectIdrequired

The id of the return to delete.

DELETE/returns/:id
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.delete('/returns/{id}', {
});