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 Values

Index

Retrieve a list of option values by making this request:

GET /api/v1/option_values

Parameters

ids:

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

option_type_id:

Specifying this parameter will display option values of respective option type.

Response

Status:
200 OK
[
{
"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 value, make a request like this:

GET /api/v1/option_values?q[name_cont]=red

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": "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_values?q[s]=name%20asc

Show

Retrieve details about a particular option value:

GET /api/v1/option_values/1

Response

Status:
200 OK
{
"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 value by making this request:

GET /api/v1/option_values/new

Response

Status:
200 OK
{
  "attributes": [
      "id", "name", "presentation", "option_type_name", "option_type_id",
      "option_type_presentation"
  ],
  "required_attributes": [
      "name", "presentation"
  ]
}

Create

This action is only accessible by an admin user.

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

POST /api/v1/option_values

For instance, a request to create a new option value called “sports” with a presentation value of “Sports” would look like this:

POST /api/v1/option_values?option_value[name]=sports&option_value[presentation]=Sports

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 an option value’s details, make this request with the necessary parameters:

PUT /api/v1/option_values/1

For instance, to update an option value’s name, send it through like this:

PUT /api/v1/option_values/1?option_value[name]=sport&option_value[presentation]=Sport

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 an option value, make this request:

DELETE /api/v1/option_values/1

This request removes an option value from database.

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