Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for 2024_1 wsdl #135

Merged
merged 4 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions netsuitesdk/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
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)
page_size=page_size, wsdl_version=wsdl_version)
ns_client.connect_tba(
consumer_key=consumer_key,
consumer_secret=consumer_secret,
Expand Down
28 changes: 22 additions & 6 deletions netsuitesdk/internal/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Zeep to connect to a NetSuite account and make requests.
"""

import re
import base64
import hashlib
import hmac
Expand Down Expand Up @@ -30,8 +31,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
Expand All @@ -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):
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
Expand All @@ -57,13 +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

self._wsdl_url = self.WSDL_URL_TEMPLATE.format(account=account.replace('_', '-'))
self._datacenter_url = self.DATACENTER_URL_TEMPLATE.format(account=account.replace('_', '-'))
self.wsdl_version = 'v2019_1_0'
self.netsuite_port_version = 'NetSuitePort_2019_1'
self.netsuite_binding_version = '2019_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=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
Expand All @@ -78,8 +92,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(self.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.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='netsuitesdk',
version='2.21.4',
version='2.22.0',
Hrishabh17 marked this conversation as resolved.
Show resolved Hide resolved
author='Siva Narayanan',
author_email='[email protected]',
description='Python SDK for accessing the NetSuite SOAP webservice',
Expand Down
Loading