waynerobinson / xeroizer

Xero accounting system API library.
http://waynerobinson.github.com/xeroizer
Other
238 stars 311 forks source link

Delete Items #475

Closed DawsonLeBrown closed 3 years ago

DawsonLeBrown commented 5 years ago

Hi,

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?

@SylarRuby seems to have asked the same thing almost three years ago on #319 , but then closed his issue on the day he asked it, so there are no replys to help me work it out.

Thanks for your help.

SophiaAP commented 5 years ago

@DawsonLeBrown The gem doesn't currently have a delete option for items. It's a bit tedious but I've just been selecting and deleting them from Xero's UI.

saramic commented 3 years ago

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

rjaus commented 3 years ago

Documented: https://github.com/waynerobinson/xeroizer/wiki/How-to-DELETE-Items

Closed, thanks for the answer @saramic