Skip to content

How to DELETE Items

Riley James edited this page Sep 21, 2021 · 1 revision

Question:

Can someone please tell me how I can delete an Item record.

According to https://developer.xero.com/documentation/api/items, the http DELETE verb can be used to delete an Item, but I cannot see how to do so with the Xeroizer gem - is this not implemented, or am I missing something?

Answer:

the client does seem to offer .delete functionality so if I wanted to delete all products with the item code TEST_ I could do

setup a client

xeroizer_client = Xeroizer::OAuth2Application.new(client_id, client_secret, access_token: access_token)

fetch items you want to delete

items = xeroizer_client.Item.all(where: 'Code.StartsWith("TEST_")')
items.each{ |item|
  uri = URI("https://api.xero.com/api.xro/2.0/Items/#{item.item_id}")
  # call delete on the client xeroizer/lib/xeroizer/oauth2.rb
  xeroizer_client.client.delete(uri.request_uri)
}

might be worth to put a sleep(1) in there and items associated with inventory tracking CANNOT be deleted