NetSuite SEARCH SAVED EXPORT
This library allows you to interact with saved searches by importing data from saved searches in Excel, CSV, and TXT formats.
Installation
pip install ns_search_saved_export
Usage
Get All date from a saved search
Use this method to obtain all the data from a saved search when the size of the data is less than 10000 records.
from ns_search_saved_export.ns_search_saved_export import NsSearchSavedExport
search_saved_id = 'customsearch33885'
api = NsSearchSavedExport(
url='https://your-netsuite-url',
consumer_key='your_consumer_key',
consumer_secret='your_consumer_secret',
token_key='your_token_key',
token_secret='your_token_secret',
realm='your_realm',
search_id=search_saved_id
)
payload = {
'searchID': search_saved_id,
}
response = api.send_request(payload)
data = api.extract_data(response)
api.save_to_excel(data)
api.save_to_csv(data)
api.save_to_txt(data)
Get data paginated from a saved search
Use this method to obtain data from a saved search when the size of the data is greater than 10000 records.
from ns_search_saved_export.ns_search_saved_export import NsSearchSavedExport
search_saved_id = 'customsearch33885'
page_index = 0
page_range = 10000
api = NsSearchSavedExport(
url='https://your-netsuite-url',
consumer_key='your_consumer_key',
consumer_secret='your_consumer_secret',
token_key='your_token_key',
token_secret='your_token_secret',
realm='your_realm',
search_id=search_saved_id
)
payload = {
'searchID': search_saved_id,
'pageIndex': page_index,
'pageRange': page_range
}
data_result = []
while True:
response = api.send_request(payload)
json_string = json.dumps(response)
data = json.loads(json_string)
results = data.get('results', [])
data_result = data_result + results
if len(results) == 0:
results = {'results': data_result}
with open(os.path.join(api.path, 'conslidado.json'), 'w', encoding='utf-8') as json_file:
json.dump(results, json_file, ensure_ascii=False, indent=4)
data = api.extract_data(results)
api.save_to_excel(data)
api.save_to_csv(data)
api.save_to_txt(data)
break
page_index += 1
Methods available
List of methods available in the library
"""POST request to obtain saved search data
Returns:
dict: POST request response
"""
response = api.send_request(payload)
"""Structured data obtained from the saved search
Args:
json_data (dict): Data obtained in the POST response
Returns:
list: List of saved search data
"""
data = api.extract_data(response)
"""Save data in Excel format
Args:
matrix (list): Search data
file_name (str) opcional: Excel file name. Default: name of the saved search
sheet_name (str optional): Excel sheet name. Default: data
"""
api.save_to_excel(data, 'data.xlsx', 'Sheet1')
"""Save data in CSV format
Args:
matrix (list): Search data. Default: name of the saved search
file_name (str) optional: CSV file name
"""
api.save_to_csv(data, 'data.csv')
"""Save data in TXT format
Args:
matrix (list): Search data
file_name (str) optional: TXT file name. Default: name of the saved search
"""
api.save_to_txt(data, 'data.txt')