Resources

Resources are sources of specific information. Individual resources are identified in requests using URLs. Each resource represents a database record or a collection of database records. The format returned can be in JSON or XML. Depending on the language you define in the endpoint, the API will return the resource in that language (the shop does need to have the language active).

Each resource will have implemented at least one request method (GET, POST, PUT, DELETE). Below are some examples using the products resource. Other resources work the same way unless a particular method is not available for that resource.

Retrieving information

Example

$ curl https://api.shoplightspeed.com/en/products.json -u {key}:{secret}
<?php
$products = $api->products->get();

Retrieving all products is done by sending a GET request to the products resource. This will return 50 products as that is the default number of results per request. This can be changed by using filtering, as described in the next section.

Filter the results

Example

$ curl https://api.shoplightspeed.com/en/products.json?page=2&limit=100 -u {key}:{secret}
<?php
// The first parameter $productId can be ignored
$products = $api->products->get(null, [
  'page' => 2,
  'limit' => 100
]);

While retrieving a resource you can apply extra GET parameters to filter the results. Available parameters are shown below. Note that not all filters work on every resource.

Parameter examples:

  • page: Page for which you want to get the results. (default: 1)
  • limit: Number of products returned by the API. (default: 50, maximum: 250)
  • since_id: Only return products with an identifier (ID) higher than the given value. (default: 0)
  • created_at_min: Show products created after date. (format: YYYY-MM-DD HH:MM:SS)
  • created_at_max: Show products created before date. (format: YYYY-MM-DD HH:MM:SS)
  • updated_at_min: Show products last updated after date. (format: YYYY-MM-DD HH:MM:SS)
  • updated_at_max: Show products last updated before date. (format: YYYY-MM-DD HH:MM:SS)
  • fields: Comma-separated list of fields to include in the response. (format: id,createdAt)
  • number
  • customerId
  • status: (‘offer’, ‘new’, ‘on_hold’, ‘processing’, ‘processing_awaiting_payment’, ‘processing_awaiting_pickup’, ‘processing_awaiting_shipment’, ‘processing_partially_paid’,processing_partially_picked_up, ‘processing_partially_shipped’, ‘completed’, ‘completed_picked_up’, ‘completed_shipped’, ‘cancelled’)
  • paymentStatus: (‘not_paid’,’partially_paid’,’paid’,’cancelled’)
  • shipmentStatus: (‘not_shipped’,’partially_shipped’,’shipped’,’cancelled’)

Retrieve one product

$ curl https://api.shoplightspeed.com/en/products/{product_id}.json -u {key}:{secret}
<?php
$productId = 123;

$product = $api->products->get($productId);

Retrieving one product is done by appending the product identifier (ID) to the products resource URL.

Retrieve the count

Example

$ curl https://api.shoplightspeed.com/en/products/count.json -u {key}:{secret}
<?php
$count = $api->products->count();

Retrieving the total number of products is done by appending /count to the products resource URL. You can also apply the same GET parameters used for retrieving products.

Creating a product

Example

curl https://api.shoplightspeed.com/en/products.json \
  -u {key}:{secret} \
  -d product[title]="My product" \
  -d product[fulltitle]="My first product"
<?php
$parameters = [
    'title' => 'My first product'
];

$product = $api->products->create($parameters);

Creating a product is done by sending a POST request to the products resource. After creating a product, the API will automatically return an array with the product information including a unique product identifier (ID). For a complete overview of all possible parameters visit the products resource page.

Update a product

Example

curl https://api.shoplightspeed.com/en/products/{product_id}.json \
  -u {key}:{secret} \
  -X "PUT" \
  -d product[title]="My product" \
  -d product[fulltitle]="My first product"
<?php
$productId = 123;

$parameters = [
    'title' => 'My modified product'
];

$product = $api->products->update($productId, $parameters);

Updating a product is done by sending a PUT request to the products resource. After updating a product, the API will automatically return the modified product information. The product identifier (ID) needs to be appended to the products resource URL. For a complete overview of all possible parameters visit the products resource page.

Deleting a product

Example

curl https://api.shoplightspeed.com/en/products/{product_id}.json \
  -u {key}:{secret} \
  -X "DELETE"
<?php
$productId = 123;

$api->products->delete($productId);

Deleting a product is done by sending a DELETE request to the products resource. The product identifier (ID) needs to be appended to the products resource URL.