APIExtensionsDeveloperUserReleasesDemoSupport
  • V 1

    • Summary
    • Address
    • Checkouts
    • Countries
    • Customer Returns
    • Line Items
    • Option Types
    • Option Values
    • Orders
    • Payments
    • Product Images
    • Product Properties
    • Products
    • Return Authorizations
    • Shipments
    • States
    • Stock Items
    • Stock Locations
    • Stock Movements
    • Taxonomies
    • Users
    • Variants
    • Zones

Table Of Contents

IndexParametersResponseSearchResponseSorting resultsShowResponseNewResponseCreateSuccessful ResponseFailed ResponseUpdateSuccessful ResponseFailed ResponseDelete

Option Types

Index

Retrieve a list of option types by making this request:

GET /api/v1/option_types

Parameters

ids:

A comma-separated list of option type ids. Specifying this parameter will display the respective option types.

Response

Status:
200 OK
{
"id": 1,
"name": "tshirt-size",
"presentation": "Size",
"position": 1,
"option_values": [
{
"id": 1,
"name": "Small",
"presentation": "S",
"option_type_name": "tshirt-size",
"option_type_id": 1,
"option_type_presentation": "S"
}
]
}

Search

To search for a specific option type, make a request like this:

GET /api/v1/option_types?q[name_cont]=color

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.

Response

Status:
200 OK
[
{
"id": 1,
"name": "tshirt-size",
"presentation": "Size",
"position": 1,
"option_values": [
{
"id": 1,
"name": "Small",
"presentation": "S",
"option_type_name": "tshirt-size",
"option_type_id": 1,
"option_type_presentation": "S"
}
]
}
]

Sorting results

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

GET /api/v1/option_types?q[s]=name%20asc

Show

Retrieve details about a particular option type:

GET /api/v1/option_types/1

Response

Status:
200 OK
{
"id": 1,
"name": "tshirt-size",
"presentation": "Size",
"position": 1,
"option_values": [
{
"id": 1,
"name": "Small",
"presentation": "S",
"option_type_name": "tshirt-size",
"option_type_id": 1,
"option_type_presentation": "S"
}
]
}

New

You can learn about the potential attributes (required and non-required) for a option type by making this request:

GET /api/v1/option_types/new

Response

Status:
200 OK
{
  "attributes": [
    "id", "name", "presentation", "position"
  ],
  "required_attributes": [
    "name", "presentation"
  ]
}

Create

This action is only accessible by an admin user.

To create a new option type through the API, make this request with the necessary parameters:

POST /api/v1/option_types

For instance, a request to create a new option type called “tshirt-category” with a presentation value of “Category” would look like this:

POST api/v1/option_types/?option_type[name]=tshirt-category&option_type[presentation]=Category

Successful Response

Status:
201 Created

Failed Response

Status:
422 Unprocessable Entity
{
  "error": "Invalid resource. Please fix errors and try again.",
  "errors": {
    "name": ["can't be blank"],
    "presentation": ["can't be blank"]
  }
}

Update

This action is only accessible by an admin user.

To update a option type’s details, make this request with the necessary parameters:

PUT /api/v1/option_types/1

For instance, to update a option types’s name, send it through like this:

PUT /api/v1/option_types/3?option_type[name]=t-category

Successful Response

Status:
201 Created

Failed Response

Status:
422 Unprocessable Entity
{
  "error": "Invalid resource. Please fix errors and try again.",
  "errors": {
    "name": ["can't be blank"],
    "presentation": ["can't be blank"]
  }
}

Delete

This action is only accessible by an admin user.

To delete a option type, make this request:

DELETE /api/v1/option_types/1

This request removes a option type from database.

Status:
204 No Content
Propose changes to this page
Maintained bySpree Commerce & Ruby on Rails developers© Spree Commerce. 2021 All Rights Reserved.