Index

To get a list of zones, make this request:

GET /api/v1/zones

Zones are paginated and can be iterated through by passing along a page parameter:

GET /api/v1/zones?page=2

Parameters

page
The page number of zone to display.
per_page
The number of zones to return per page

Response

Status: 200 OK
{
  "zones": [
    {
      "id": 1,
      "name": "America",
      "description": "The US",
      "zone_members": [
        {
          "id": 1,
          "name": "United States",
          "zoneable_type": "Spree::Country",
          "zoneable_id": 1
        }
      ]
    }
  ],
  "count": 25,
  "pages": 5,
  "current_page": 1
}

To search for a particular zone, make a request like this:

GET /api/v1/zones?q[name_cont]=north

The searching API is provided through the Ransack gem which Spree depends on. The name_cont here is called a predicate, and you can learn more about them by reading about Predicates on the Ransack wiki.

The search results are paginated.

Response

Status: 200 OK
{
  "zones": [
    {
      "id": 1,
      "name": "America",
      "description": "The US",
      "zone_members": [
        {
          "id": 1,
          "name": "United States",
          "zoneable_type": "Spree::Country",
          "zoneable_id": 1
        }
      ]
    }
  ],
  "count": 25,
  "pages": 5,
  "current_page": 1
}

Sorting results

Results can be returned in a specific order by specifying which field to sort by when making a request.

GET /api/v1/zones?q[s]=name%20desc

Show

To get information for a single zone, make this request:

GET /api/v1/zones/1

Response

Status: 200 OK
{
  "id": 1,
  "name": "America",
  "description": "The US",
  "zone_members": [
    {
      "id": 1,
      "name": "United States",
      "zoneable_type": "Spree::Country",
      "zoneable_id": 1
    }
  ]
}

Create

This action is only accessible by an admin user.

To create a zone, make a request like this:

POST /api/v1/zones

Assuming in this instance that you want to create a zone containing a zone member which is a Spree::Country record with the id attribute of 1, send through the parameters like this:

{
  "zone": {
    "name": "North Pole",
    "zone_members": [
      {
        "zoneable_type": "Spree::Country",
        "zoneable_id": 1
      }
    ]
  }
}

Response

Status: 201 Created
{
  "id": 1,
  "name": "America",
  "description": "The US",
  "zone_members": [
    {
      "id": 1,
      "name": "United States",
      "zoneable_type": "Spree::Country",
      "zoneable_id": 1
    }
  ]
}

Update

This action is only accessible by an admin user.

To update a zone, make a request like this:

PUT /api/v1/zones/1

To update zone and zone member information, use parameters like this:

{
  "id": 1,
  "zone": {
    "name": "North Pole",
    "zone_members": [
      {
        "zoneable_type": "Spree::Country",
        "zoneable_id": 1
      }
    ]
  }
}

Response

Status: 200 OK
{
  "id": 1,
  "name": "America",
  "description": "The US",
  "zone_members": [
    {
      "id": 1,
      "name": "United States",
      "zoneable_type": "Spree::Country",
      "zoneable_id": 1
    }
  ]
}

Delete

This action is only accessible by an admin user.

To delete a zone, make a request like this:

DELETE /api/v1/zones/1

This request will also delete any related zone_member records.

Response

Status: 204 No Content