Commerce Layer will be proud to sponsor the next JAMstack Conf in London — 09-10 July, 2019 🎉 Stay tuned!

API REFERENCE

Markets

A market is made of a merchant, an inventory model and a price list (plus an optional geocoder and tax calculator). Channel applications must specify a market scope when obtaining an access token. This way, all the resources (e.g., SKUs, prices, stock items) are automatically filtered.

The market object

A Market object is returned as part of the response body of each successful create, list, retrieve or update API call. The following table contains the list of all its fields along with their type, description and example values.

Object fields:
name
string
The market's internal name
Example:
EU Market
facebook_pixel_id
string
The Facebook Pixed ID
Example:
1234567890
id
integer
Unique identifier for the resource.
Example:
1234
created_at
datetime
Time at which the resource was created.
Example:
2018-01-01T12:00:00.000Z
updated_at
datetime
Time at which the resource was last updated.
Example:
2018-01-01T12:00:00.000Z
reference
string
A string that you can use to add your own identifier to the resource. This can be useful for intergrating the resource to an external system, like an ERP, a marketing tool or a CRM.
Example:
ANYREFEFERNCE
metadata
object
Set of key-value pairs that you can attach to the resource. This can be useful for storing additional information about the resource in a structured format.
Example:
{"foo":"bar"}
relationship (N:1)
The associated merchant.
relationship (N:1)
The associated price list.
relationship (N:1)
The associated inventoty model.

Create a market

To create a new market, send a POST request to the /api/markets endpoint, passing the resource arguments in the request body. The following table contains the list of all the possible arguments, along with their type, description and examples values. All the arguments marked as required must be present in the request.

Arguments:
name
required
The market's internal name
Example:
EU Market
facebook_pixel_id
optional
The Facebook Pixed ID
Example:
1234567890
reference
optional
A string that you can use to add your own identifier to the resource. This can be useful for intergrating the resource to an external system, like an ERP, a marketing tool or a CRM.
Example:
ANYREFEFERNCE
metadata
optional
Set of key-value pairs that you can attach to the resource. This can be useful for storing additional information about the resource in a structured format.
Example:
{"foo":"bar"}
required
The associated merchant.
required
The associated price list.
required
The associated inventoty model.
Example request:
POST /api/markets HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
  "data": {
    "type": "markets",
    "attributes": {
      "name": "EU Market"
    },
    "relationships": {
      "merchant": {
        "data": {
          "type": "merchants",
          "id": "1234"
        }
      },
      "price_list": {
        "data": {
          "type": "price_lists",
          "id": "1234"
        }
      },
      "inventory_model": {
        "data": {
          "type": "inventory_models",
          "id": "1234"
        }
      }
    }
  }
}
Example response:
HTTP/1.1 201 Created
Content-Type: application/vnd.api+json

{
  "data": {
    "id": "1234",
    "type": "markets",
    "links": {
      "self": "https://your-brand.commercelayer.io/api/markets/1234"
    },
    "attributes": {
      "name": "EU Market",
      "facebook_pixel_id": "1234567890",
      "id": "1234",
      "created_at": "2018-01-01T12:00:00.000Z",
      "updated_at": "2018-01-01T12:00:00.000Z",
      "reference": "ANYREFEFERNCE",
      "metadata": {
        "foo": "bar"
      }
    },
    "relationships": {
      "merchant": {
        "links": {
          "self": "https://your-brand.commercelayer.io/api/markets/1234/relationships/merchant",
          "related": "https://your-brand.commercelayer.io/api/markets/1234/merchant"
        }
      },
      "price_list": {
        "links": {
          "self": "https://your-brand.commercelayer.io/api/markets/1234/relationships/price_list",
          "related": "https://your-brand.commercelayer.io/api/markets/1234/price_list"
        }
      },
      "inventory_model": {
        "links": {
          "self": "https://your-brand.commercelayer.io/api/markets/1234/relationships/inventory_model",
          "related": "https://your-brand.commercelayer.io/api/markets/1234/inventory_model"
        }
      }
    },
    "meta": {
      "mode": "test"
    }
  }
}

List all markets

To fetch a collection of markets, send a GET request to the /api/markets endpoint.

Example request:
GET /api/markets HTTP/1.1
Accept: application/vnd.api+json
Example response:
HTTP/1.1 200 OK
Content-Type: application/vnd.api+json

{
  "data": [
    {
      "id": "1234",
      "type": "markets",
      "links": {
        "self": "https://your-brand.commercelayer.io/api/markets/1234"
      },
      "attributes": {
        "name": "EU Market",
        "facebook_pixel_id": "1234567890",
        "id": "1234",
        "created_at": "2018-01-01T12:00:00.000Z",
        "updated_at": "2018-01-01T12:00:00.000Z",
        "reference": "ANYREFEFERNCE",
        "metadata": {
          "foo": "bar"
        }
      },
      "relationships": {
        "merchant": {
          "links": {
            "self": "https://your-brand.commercelayer.io/api/markets/1234/relationships/merchant",
            "related": "https://your-brand.commercelayer.io/api/markets/1234/merchant"
          }
        },
        "price_list": {
          "links": {
            "self": "https://your-brand.commercelayer.io/api/markets/1234/relationships/price_list",
            "related": "https://your-brand.commercelayer.io/api/markets/1234/price_list"
          }
        },
        "inventory_model": {
          "links": {
            "self": "https://your-brand.commercelayer.io/api/markets/1234/relationships/inventory_model",
            "related": "https://your-brand.commercelayer.io/api/markets/1234/inventory_model"
          }
        }
      },
      "meta": {
        "mode": "test"
      }
    },
    {
      "other": "... 24 markets (first page)"
    }
  ],
  "meta": {
    "record_count": 125,
    "page_count": 5
  },
  "links": {
    "first": "/api/markets?page[number]=1&page[size]=25",
    "prev": "/api/markets?page[number]=2&page[size]=25",
    "next": "/api/markets?page[number]=4&page[size]=25",
    "last": "/api/markets?page[number]=5&page[size]=25"
  }
}
Available filters
id q reference ids created_at_from created_at_to updated_at_from updated_at_to
Sortable attributes
name id created_at updated_at reference

Retrieve a market

To fetch a single market, send a GET request to the /api/markets/{{id}} endpoint, where {{id}} is the id of the resource that you want to retrieve.

Example request:
GET /api/markets/1234 HTTP/1.1
Accept: application/vnd.api+json
Example response:
HTTP/1.1 200 OK
Content-Type: application/vnd.api+json

{
  "data": {
    "id": "1234",
    "type": "markets",
    "links": {
      "self": "https://your-brand.commercelayer.io/api/markets/1234"
    },
    "attributes": {
      "name": "EU Market",
      "facebook_pixel_id": "1234567890",
      "id": "1234",
      "created_at": "2018-01-01T12:00:00.000Z",
      "updated_at": "2018-01-01T12:00:00.000Z",
      "reference": "ANYREFEFERNCE",
      "metadata": {
        "foo": "bar"
      }
    },
    "relationships": {
      "merchant": {
        "links": {
          "self": "https://your-brand.commercelayer.io/api/markets/1234/relationships/merchant",
          "related": "https://your-brand.commercelayer.io/api/markets/1234/merchant"
        }
      },
      "price_list": {
        "links": {
          "self": "https://your-brand.commercelayer.io/api/markets/1234/relationships/price_list",
          "related": "https://your-brand.commercelayer.io/api/markets/1234/price_list"
        }
      },
      "inventory_model": {
        "links": {
          "self": "https://your-brand.commercelayer.io/api/markets/1234/relationships/inventory_model",
          "related": "https://your-brand.commercelayer.io/api/markets/1234/inventory_model"
        }
      }
    },
    "meta": {
      "mode": "test"
    }
  }
}

Update a market

To update an existing market, send a PATCH request to the /api/markets/{{id}} endpoint, where {{id}} is the id of the resource that you want to update. The following table contains the list of all the possible arguments that you can pass with the request body, along with their type, description and examples values. Please note that all arguments are optional.

Arguments:
name
optional
The market's internal name
Example:
EU Market
facebook_pixel_id
optional
The Facebook Pixed ID
Example:
1234567890
reference
optional
A string that you can use to add your own identifier to the resource. This can be useful for intergrating the resource to an external system, like an ERP, a marketing tool or a CRM.
Example:
ANYREFEFERNCE
metadata
optional
Set of key-value pairs that you can attach to the resource. This can be useful for storing additional information about the resource in a structured format.
Example:
{"foo":"bar"}
optional
The associated merchant.
optional
The associated price list.
optional
The associated inventoty model.
Example request:
PATCH /api/markets/1234 HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
  "data": {
    "type": "markets",
    "id": 1234,
    "attributes": {
      "name": "EU Market"
    },
    "relationships": {
    }
  }
}
Example response:
HTTP/1.1 201 Created
Content-Type: application/vnd.api+json

{
  "data": {
    "id": "1234",
    "type": "markets",
    "links": {
      "self": "https://your-brand.commercelayer.io/api/markets/1234"
    },
    "attributes": {
      "name": "EU Market",
      "facebook_pixel_id": "1234567890",
      "id": "1234",
      "created_at": "2018-01-01T12:00:00.000Z",
      "updated_at": "2018-01-01T12:00:00.000Z",
      "reference": "ANYREFEFERNCE",
      "metadata": {
        "foo": "bar"
      }
    },
    "relationships": {
      "merchant": {
        "links": {
          "self": "https://your-brand.commercelayer.io/api/markets/1234/relationships/merchant",
          "related": "https://your-brand.commercelayer.io/api/markets/1234/merchant"
        }
      },
      "price_list": {
        "links": {
          "self": "https://your-brand.commercelayer.io/api/markets/1234/relationships/price_list",
          "related": "https://your-brand.commercelayer.io/api/markets/1234/price_list"
        }
      },
      "inventory_model": {
        "links": {
          "self": "https://your-brand.commercelayer.io/api/markets/1234/relationships/inventory_model",
          "related": "https://your-brand.commercelayer.io/api/markets/1234/inventory_model"
        }
      }
    },
    "meta": {
      "mode": "test"
    }
  }
}

Delete a market

To delete a market, send a DELETE request to the /api/markets/{{id}} endpoint, where {{id}} is the id of the resource that you want to delete.

Example request:
DELETE /api/markets/1234 HTTP/1.1
Accept: application/vnd.api+json
Example response:
HTTP/1.1 204 No Content