Happy Business Starts Here

Re: How can I remove or delete all the data in my API Sandbox Environment?

Zuora Support Moderator

How can I remove or delete all the data in my API Sandbox Environment?

Question: How can I remove or delete all the data in my API Sandbox Environment?



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

1 ACCEPTED SOLUTION

Accepted Solutions
Zuora Support Moderator

Re: How can I remove or delete all the data in my API Sandbox Environment?

Answer: 

If you're looking to just clean up your current sandbox (clean slate), you can do the following:
 
  • Delete the accounts in the sandbox. If an account is deleted, all data associated with this account -- including subscriptions, invoices, payments, and adjustments -- will also be deleted. Thus, there's no need for you to delete these other objects.
  • After the accounts are deleted, you can delete the products in the product catalog
There are two methods to delete:
  1. Manually
  2. Using APIs to delete:
  •  SOAP: delete() call -- The delete() call can support a maximum of 50 IDs at a time as long as the IDs are of the same type. The ID you need to pass on your delete() call is the Account ID.
Here's a sample delete() call for multiple Accounts:
<ns1:delete>
<ns1:type>Account</ns1:type>
<ns1:ids>2c92a0fb3cc919c7013ccf25b02d674d123</ns1:ids>
<ns1:ids>2c92a0fb3cc919c7013ccf25b02d6d7szyw</ns1:ids>
<ns1:ids>2c92a0fb3cc919c7013ccf25b02d623s0zk</ns1:ids>
</ns1:delete>
There are request samples that can be found in our developer center: https://www.zuora.com/developer/api-reference/
 
KEY NOTES:
  • If an account has been deleted, regardless if it is in a sandbox or production environment, Zuora does not support the process of recovering these objects. These objects should be recreated.
  • If you have linked your sandbox to a sandbox SFDC instance (Quotes / 360 Sync), your old products from the product catalog will continue syncing, though your users should not be able to use them any longer. Please be aware that this could impact how much data is being transferred over, as your SFDC sandbox has a limited amount of space.


If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

View solution in original post

4 REPLIES 4
Zuora Support Moderator

Re: How can I remove or delete all the data in my API Sandbox Environment?

Answer: 

If you're looking to just clean up your current sandbox (clean slate), you can do the following:
 
  • Delete the accounts in the sandbox. If an account is deleted, all data associated with this account -- including subscriptions, invoices, payments, and adjustments -- will also be deleted. Thus, there's no need for you to delete these other objects.
  • After the accounts are deleted, you can delete the products in the product catalog
There are two methods to delete:
  1. Manually
  2. Using APIs to delete:
  •  SOAP: delete() call -- The delete() call can support a maximum of 50 IDs at a time as long as the IDs are of the same type. The ID you need to pass on your delete() call is the Account ID.
Here's a sample delete() call for multiple Accounts:
<ns1:delete>
<ns1:type>Account</ns1:type>
<ns1:ids>2c92a0fb3cc919c7013ccf25b02d674d123</ns1:ids>
<ns1:ids>2c92a0fb3cc919c7013ccf25b02d6d7szyw</ns1:ids>
<ns1:ids>2c92a0fb3cc919c7013ccf25b02d623s0zk</ns1:ids>
</ns1:delete>
There are request samples that can be found in our developer center: https://www.zuora.com/developer/api-reference/
 
KEY NOTES:
  • If an account has been deleted, regardless if it is in a sandbox or production environment, Zuora does not support the process of recovering these objects. These objects should be recreated.
  • If you have linked your sandbox to a sandbox SFDC instance (Quotes / 360 Sync), your old products from the product catalog will continue syncing, though your users should not be able to use them any longer. Please be aware that this could impact how much data is being transferred over, as your SFDC sandbox has a limited amount of space.


If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

View solution in original post

Master

Re: How can I remove or delete all the data in my API Sandbox Environment?

The following python script does this; I wrote it as part of my migration effort. It references a wrapper for the Zuora REST API that is here: https://github.com/bolaurent/zuora-restful-python.

 

If you have subscriptions with different billto and ownedby subscriptions, you have to delete the owners first. This script also limits the accounts it will delete to those that were created by the migration scripts; this allows my users to keep the test data that they have entered by hand.

 

If you have journal entries, you'll have to delete those first.

 

#!/usr/local/bin/python3

import pdb
from progressbar import ProgressBar


import sys
sys.path.append('../rest')
sys.path.append('../utility')
import config

# https://github.com/bolaurent/zuora-restful-python from zuora import Zuora ZUORA_CHUNKSIZE = 20 # return a set of zuora account ids for accounts that own invoices on subscriptions def getZuoraSubsriptionInvoiceAccounts(zuora): accountIds = [] result = zuora.query("select Id, AccountId, InvoiceOwnerId, AccountId from Subscription where CreatedById = '{}'".format(config.ZUORA_API_USERID)) if result['size'] > 0: accountIds = [record['InvoiceOwnerId'] for record in result['records'] if record['InvoiceOwnerId'] != record['AccountId']] return accountIds def getAllAccountIds(zuora): accountIds = [] result = zuora.query("select Id from Account where CreatedById = '{}'".format(config.ZUORA_API_USERID)) if result['size'] > 0: accountIds = [record['Id'] for record in result['records']] return accountIds def getFirstBatch(zuora): allAccountIds = getAllAccountIds(zuora) invoiceOwnerAccountIds = getZuoraSubsriptionInvoiceAccounts(zuora) simpleOwnerAccountIds = [id for id in allAccountIds if id not in invoiceOwnerAccountIds] return simpleOwnerAccountIds def deleteMigratedAccounts(zuora): deletedCount = 0 firstBatch = getFirstBatch(zuora) if len(firstBatch): deletedCount += len(firstBatch) deleteAccounts(zuora, firstBatch) secondBatch = getAllAccountIds(zuora) if len(secondBatch): deletedCount += len(secondBatch) deleteAccounts(zuora, secondBatch) print("deleted {} accounts".format(deletedCount)) def deleteAccounts(zuora, ids): progressbar = ProgressBar() chunks = [ids[i:i + ZUORA_CHUNKSIZE] for i in range(0, len(ids), ZUORA_CHUNKSIZE)] for chunk in progressbar(chunks): results = zuora.delete('Account', chunk) for result in results: if not result['success']: print(result) def main(): zuora = Zuora(config.zuoraConfig) deleteMigratedAccounts(zuora) pass if __name__ == "__main__": main() pass

 

Master

Re: How can I remove or delete all the data in my API Sandbox Environment?

@AmyLy@bolaurent

 

These information is very useful for me!!
I was particularly helped with the attention when the Subscription's ownedby ("Customer Name") and billto ("Invoice Owner") are different.

Zuora Support Moderator

Re: How can I remove or delete all the data in my API Sandbox Environment?

@yamasaki1ma - I'm glad you found it useful! Feel free to share anything new or interesting you've discovered as you work with Zuora. It's always great to build up the content in the Community. Have a great start to your weekend!



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √