Skip to main content

A library for interacting with NetSuite API and exporting data

Project description

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

# Obtain the saved search ID
search_saved_id = 'customsearch33885' # Replace with your saved search ID

# Initialize the API
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
)

# Send request
payload = {
    'searchID': search_saved_id, # Replace with your saved search ID
}

# Obtain the data
response = api.send_request(payload)

# Extract data
data = api.extract_data(response)

# Save data to Excel
api.save_to_excel(data)

# Save data to CSV
api.save_to_csv(data)

# Save data to TXT
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

# Obtain the saved search ID
search_saved_id = 'customsearch33885' # Replace with your saved search ID
page_index = 0
page_range = 10000

# Initialize the API
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
)
# Send request
# Note: the values of pageIndex and pageRange are optional but both must be sent in case you want to obtain the data of a page

payload = {
    'searchID': search_saved_id, # Replace with your saved search ID
    'pageIndex': page_index, # Replace with your page index. Default: 0 (first page) add 1 to get the next page
    'pageRange': page_range # Replace with your page range. Default: 1000 (first page) add 1000 to get the next page. Maximum: 10000
}

data_result = []
while True:
    # Send request
    response = api.send_request(payload)

    # Convertir el diccionario a una cadena JSON
    json_string = json.dumps(response)

    # Convertir la cadena JSON de nuevo a un diccionario
    data = json.loads(json_string)

    # Extraer la lista de resultados
    results = data.get('results', [])
    
    data_result = data_result + results
    
    if len(results) == 0:
        results = {'results': data_result}

        # Optional: save the data to a file
        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)

        # Extract data
        data = api.extract_data(results)

        # Save data to Excel
        api.save_to_excel(data)

        # Save data to CSV
        api.save_to_csv(data)

        # Save data to TXT
        api.save_to_txt(data)
        break
    
    page_index += 1  
    

Methods available

List of methods available in the library

# Obtain the data
"""POST request to obtain saved search data

Returns:
    dict: POST request response    
"""
response = api.send_request(payload)

# Extract data
"""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 to Excel
"""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 to CSV
"""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 to TXT
"""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')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ns_search_saved_export-0.1.22.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

ns_search_saved_export-0.1.22-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file ns_search_saved_export-0.1.22.tar.gz.

File metadata

File hashes

Hashes for ns_search_saved_export-0.1.22.tar.gz
Algorithm Hash digest
SHA256 f3af6a0b643a374c9bd2a096cb9200c142a07ae7466809b852f43a4f6f6eb89e
MD5 86cc1815c5ffb5b3e51535b99b7117de
BLAKE2b-256 b568c9e28ecafaea530ac6d7b2e0a4461f887cd2eeee42f7f1d2361c06fd5e6d

See more details on using hashes here.

File details

Details for the file ns_search_saved_export-0.1.22-py3-none-any.whl.

File metadata

File hashes

Hashes for ns_search_saved_export-0.1.22-py3-none-any.whl
Algorithm Hash digest
SHA256 7d74453a9b6386fb9863600e2c54728dd764d7e83b28dd0b62d630ce134fca98
MD5 8f51a3bfb743a512716a6481647a15d5
BLAKE2b-256 c85c9375612a7b30dbac299f3ea9ab5f201bee1b1b88c9fe4bbdd3abf6d5f809

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page