Developing Shopify Apps, Part 5: Deleting Items

Joey Devilla


In the previous articles in this series, Developing Shopify Apps, we've looked at getting items, creating new items and modifying existing items -- the C, R and U of "CRUD": creating, reporting and updating. In this article, we'll look at the final remaining CRUD operation, deleting items.

Deleting Customers

Let's try deleting a customer. Once again, we'll go with our good example friend Peter Griffin, whose ID is known to be 51827492. Here are the HTTP verbs and URLs for deleting his record:

  • DELETE api-key:password@shop-url/admin/customers/51827492.xml (XML version)
  • DELETE api-key:password@shop-url/admin/customers/51827492.json (JSON version)

For this example, we'll use the XML version. Here's what happens when you perform the delete operation:

  • If there is a customer with the specified ID, the API responds with:
    • A "200 OK" header, indicating that the customer has been deleted from the shop's records
    • An empty response body
  • If there isn't a customer with the specified ID, the API responds with:
    • A "404 Not found" header, indicating that there was no such customer in the shop's records
    • An empty response body

Note that the Shopify API won't let you delete a customer if s/he has any existing orders. That's because all orders must have a customer associated with them. In order to delete a customer, you'll need to delete any orders belonging to that customer first.

Deleting Products

We'll now try deleting a product. Let's go with our example product, the Stumpy Pepys drum, whose ID is 48339792. Here are the HTTP verbs and URLs for deleting it from the shop's products:

  • DELETE api-key:password@shop-url/admin/products/48339792.xml (XML)
  • DELETE api-key:password@shop-url/admin/products/48339792.json (JSON)

For this example, we'll use the JSON version. Here's what happens when you perform the delete operation:

  • If there is a product with the specified ID, the API responds with:
    • A "200 OK" header, indicating that the product has been deleted from the shop's records
    • An empty response body
  • If there isn't a customer with the specified ID, the API responds with:
    • A "404 Not found" header, indicating that there was no such product in the shop's records
    • An empty response body

Deleting Items: The General Formula

In general, the HTTP verbs and URLs for deleting items using the Shopify API are:

  • DELETE api-key:password@shop-url/admin/plural-resource-name/item-id.xml (XML)
  • DELETE api-key:password@shop-url/admin/plural-resource-name/item-id.json (JSON)

Where We Are Now

At this point, we've covered these aspects of the Shopify API:

  • Retrieving whole lists of various items (articles, blogs, customers, products and so on) as well as individual items given their ID
  • Creating new items
  • Modifying existing items
  • Deleting items

These very basic operations, often collectively referred to as "CRUD" -- Create / Report / Update / Delete -- form the basis of Shopify apps. Every app is made up of some combination of these operations performed on the various resources that the Shopify API exposes.

What's Coming Next

Now that we've covered the four basic operations behind every Shopify app, it's time to cover the resources that they operate on. In the next few articles in this series, we'll look at resources like articles, blogs, customers, order, products and other resources that you can operate on through the API.