From 0eb1168446c5f4d5eda9438857ace012eef0fbff Mon Sep 17 00:00:00 2001 From: Hrishabh Tiwari Date: Mon, 5 Aug 2024 20:52:56 +0530 Subject: [PATCH 1/4] add support for 2024_1 wsdl --- netsuitesdk/connection.py | 4 ++-- netsuitesdk/internal/client.py | 23 +++++++++++++++++------ setup.py | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/netsuitesdk/connection.py b/netsuitesdk/connection.py index 6ba3d97..e408d52 100644 --- a/netsuitesdk/connection.py +++ b/netsuitesdk/connection.py @@ -36,10 +36,10 @@ class NetSuiteConnection: def __init__(self, account, consumer_key, consumer_secret, token_key, token_secret, caching=True, caching_timeout=2592000, caching_path=None, - search_body_fields_only=True, page_size: int = 100): + search_body_fields_only=True, page_size: int = 100, use_2024_wsdl: bool = False): ns_client = NetSuiteClient(account=account, caching=caching, caching_timeout=caching_timeout, caching_path=caching_path, search_body_fields_only=search_body_fields_only, - page_size=page_size) + page_size=page_size, use_2024_wsdl=use_2024_wsdl) ns_client.connect_tba( consumer_key=consumer_key, consumer_secret=consumer_secret, diff --git a/netsuitesdk/internal/client.py b/netsuitesdk/internal/client.py index 92a1d87..46ddfac 100644 --- a/netsuitesdk/internal/client.py +++ b/netsuitesdk/internal/client.py @@ -30,8 +30,8 @@ class NetSuiteClient: """The Netsuite client class providing access to the Netsuite SOAP/WSDL web service""" - WSDL_URL_TEMPLATE = 'https://{account}.suitetalk.api.netsuite.com/wsdl/v2019_1_0/netsuite.wsdl' - DATACENTER_URL_TEMPLATE = 'https://{account}.suitetalk.api.netsuite.com/services/NetSuitePort_2019_1' + WSDL_URL_TEMPLATE = 'https://{account}.suitetalk.api.netsuite.com/wsdl/{wsdl_version}/netsuite.wsdl' + DATACENTER_URL_TEMPLATE = 'https://{account}.suitetalk.api.netsuite.com/services/{netsuite_port_version}' _search_preferences = None _passport = None @@ -45,7 +45,7 @@ class NetSuiteClient: _app_id = None def __init__(self, account=None, caching=True, caching_timeout=2592000, caching_path=None, search_body_fields_only=True, - page_size: int = 100): + page_size: int = 100, use_2024_wsdl: bool = False): """ Initialize the Zeep SOAP client, parse the xsd specifications of Netsuite and store the complex types as attributes of this @@ -62,8 +62,17 @@ def __init__(self, account=None, caching=True, caching_timeout=2592000, caching_ assert '-' not in account, 'Account cannot have hyphens, it is likely an underscore' self._account = account - self._wsdl_url = self.WSDL_URL_TEMPLATE.format(account=account.replace('_', '-')) - self._datacenter_url = self.DATACENTER_URL_TEMPLATE.format(account=account.replace('_', '-')) + wsdl_version = 'v2019_1_0' + netsuite_port_version = 'NetSuitePort_2019_1' + netsuite_binding_version = '2019_1' + + if use_2024_wsdl: + wsdl_version = 'v2024_1_0' + netsuite_port_version = 'NetSuitePort_2024_1' + netsuite_binding_version = '2024_1' + + self._wsdl_url = self.WSDL_URL_TEMPLATE.format(account=account.replace('_', '-'), wsdl_version=wsdl_version) + self._datacenter_url = self.DATACENTER_URL_TEMPLATE.format(account=account.replace('_', '-'), netsuite_port_version=netsuite_port_version) if caching: base_path = os.path.dirname(os.path.abspath(__file__)) if not caching_path else caching_path @@ -78,8 +87,10 @@ def __init__(self, account=None, caching=True, caching_timeout=2592000, caching_ self._client = Client(self._wsdl_url, transport=transport) # default service points to wrong data center. need to create a new service proxy and replace the default one + netsuite_binding_str = '{{urn:platform_{0}.webservices.netsuite.com}}NetSuiteBinding'.format(netsuite_binding_version) self._service_proxy = self._client.create_service( - '{urn:platform_2019_1.webservices.netsuite.com}NetSuiteBinding', self._datacenter_url) + netsuite_binding_str, self._datacenter_url + ) # Parse all complex types specified in :const:`~netsuitesdk.netsuite_types.COMPLEX_TYPES` # and store them as attributes of this instance. Same for simple types. diff --git a/setup.py b/setup.py index eb4bb77..acf6709 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name='netsuitesdk', - version='2.21.4', + version='2.22.0', author='Siva Narayanan', author_email='siva@fyle.in', description='Python SDK for accessing the NetSuite SOAP webservice', From b5423c43661d880ccd08912189c03ac97dd99a9c Mon Sep 17 00:00:00 2001 From: Hrishabh Tiwari Date: Mon, 5 Aug 2024 21:19:39 +0530 Subject: [PATCH 2/4] allow any version --- netsuitesdk/connection.py | 5 +++-- netsuitesdk/internal/client.py | 27 ++++++++++++++++----------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/netsuitesdk/connection.py b/netsuitesdk/connection.py index e408d52..93e3651 100644 --- a/netsuitesdk/connection.py +++ b/netsuitesdk/connection.py @@ -36,10 +36,11 @@ class NetSuiteConnection: def __init__(self, account, consumer_key, consumer_secret, token_key, token_secret, caching=True, caching_timeout=2592000, caching_path=None, - search_body_fields_only=True, page_size: int = 100, use_2024_wsdl: bool = False): + search_body_fields_only=True, page_size: int = 100, wsdl_version: str = None): + ns_client = NetSuiteClient(account=account, caching=caching, caching_timeout=caching_timeout, caching_path=caching_path, search_body_fields_only=search_body_fields_only, - page_size=page_size, use_2024_wsdl=use_2024_wsdl) + page_size=page_size, wsdl_version=wsdl_version) ns_client.connect_tba( consumer_key=consumer_key, consumer_secret=consumer_secret, diff --git a/netsuitesdk/internal/client.py b/netsuitesdk/internal/client.py index 46ddfac..56e921c 100644 --- a/netsuitesdk/internal/client.py +++ b/netsuitesdk/internal/client.py @@ -3,6 +3,7 @@ Zeep to connect to a NetSuite account and make requests. """ +import re import base64 import hashlib import hmac @@ -45,7 +46,7 @@ class NetSuiteClient: _app_id = None def __init__(self, account=None, caching=True, caching_timeout=2592000, caching_path=None, search_body_fields_only=True, - page_size: int = 100, use_2024_wsdl: bool = False): + page_size: int = 100, wsdl_version: str = None): """ Initialize the Zeep SOAP client, parse the xsd specifications of Netsuite and store the complex types as attributes of this @@ -57,22 +58,26 @@ def __init__(self, account=None, caching=True, caching_timeout=2592000, caching_ If None, defaults to 30 days :param str caching_path: Sqlite base file path. Default to python library path. """ + if wsdl_version: + if not re.match(r'^\d{4}_(\d{1,2})?$', wsdl_version): + raise ValueError("Invalid wsdl_version format. It should be in the following format: year_version eg: '2023_1'") + self.logger = logging.getLogger(self.__class__.__name__) assert account, 'Invalid account' assert '-' not in account, 'Account cannot have hyphens, it is likely an underscore' self._account = account - wsdl_version = 'v2019_1_0' - netsuite_port_version = 'NetSuitePort_2019_1' - netsuite_binding_version = '2019_1' + self.wsdl_version = 'v2019_1_0' + self.netsuite_port_version = 'NetSuitePort_2019_1' + self.netsuite_binding_version = '2019_1' - if use_2024_wsdl: - wsdl_version = 'v2024_1_0' - netsuite_port_version = 'NetSuitePort_2024_1' - netsuite_binding_version = '2024_1' + if wsdl_version: + self.wsdl_version = 'v{wsdl_version}_0'.format(wsdl_version=wsdl_version) + self.netsuite_port_version = 'NetSuitePort_{wsdl_version}'.format(wsdl_version=wsdl_version) + self.netsuite_binding_version = wsdl_version - self._wsdl_url = self.WSDL_URL_TEMPLATE.format(account=account.replace('_', '-'), wsdl_version=wsdl_version) - self._datacenter_url = self.DATACENTER_URL_TEMPLATE.format(account=account.replace('_', '-'), netsuite_port_version=netsuite_port_version) + self._wsdl_url = self.WSDL_URL_TEMPLATE.format(account=account.replace('_', '-'), wsdl_version=self.wsdl_version) + self._datacenter_url = self.DATACENTER_URL_TEMPLATE.format(account=account.replace('_', '-'), netsuite_port_version=self.netsuite_port_version) if caching: base_path = os.path.dirname(os.path.abspath(__file__)) if not caching_path else caching_path @@ -87,7 +92,7 @@ def __init__(self, account=None, caching=True, caching_timeout=2592000, caching_ self._client = Client(self._wsdl_url, transport=transport) # default service points to wrong data center. need to create a new service proxy and replace the default one - netsuite_binding_str = '{{urn:platform_{0}.webservices.netsuite.com}}NetSuiteBinding'.format(netsuite_binding_version) + netsuite_binding_str = '{{urn:platform_{0}.webservices.netsuite.com}}NetSuiteBinding'.format(self.netsuite_binding_version) self._service_proxy = self._client.create_service( netsuite_binding_str, self._datacenter_url ) From 24dfbafde164e4a5dcd28c7b71c06123829a2aec Mon Sep 17 00:00:00 2001 From: Hrishabh Tiwari Date: Tue, 6 Aug 2024 10:10:22 +0530 Subject: [PATCH 3/4] update readme --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 54549db..4a87875 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ export NS_TOKEN_SECRET=xxxx The following snippet shows how to use TBA to initialize the SDK. +## Note: By default the SDK implementation is using the wsdl version '2019_1', if you wish to use other than the default wsdl version, you can pass an optional wsdl_version. The wsdl_version should be in following format: 'year_version' eg. '2023_1' or '2022_2' etc. + ```python import os import itertools @@ -45,7 +47,9 @@ def connect_tba(): consumer_key=NS_CONSUMER_KEY, consumer_secret=NS_CONSUMER_SECRET, token_key=NS_TOKEN_KEY, - token_secret=NS_TOKEN_SECRET + token_secret=NS_TOKEN_SECRET, + #optional wsdl_version to use version other than '2019_1' + wsdl_version='2023_2' ) return nc From b9b7b6199c991b9817099dc4d3af8c28e91b37a6 Mon Sep 17 00:00:00 2001 From: Hrishabh Tiwari <74908943+Hrishabh17@users.noreply.github.com> Date: Tue, 6 Aug 2024 10:13:48 +0530 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4a87875..a9a6c54 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ export NS_TOKEN_SECRET=xxxx The following snippet shows how to use TBA to initialize the SDK. -## Note: By default the SDK implementation is using the wsdl version '2019_1', if you wish to use other than the default wsdl version, you can pass an optional wsdl_version. The wsdl_version should be in following format: 'year_version' eg. '2023_1' or '2022_2' etc. +Note: By default the SDK implementation is using the wsdl version '2019_1', if you wish to use other than the default wsdl version, you can pass an optional wsdl_version. The wsdl_version should be in following format: 'year_version' eg. '2023_1' or '2022_2' etc. ```python import os