访问netsuite soap webservice的python sdk

netsuitesdk的Python项目详细描述


netsuite sdk py

netsuite sdk py是一个python sdk,使用soap客户端库zeep(https://python-zeep.readthedocs.io/en/master/)通过netsuite soap web服务suitetalk(http://www.netsuite.com/portal/platform/developer/suitetalk.shtml)访问netsuite资源。

安装

$ pip install netsuitesdk 

备注:这个python netsuite sdk使用soap/wsdl库Zeep,在运行上述pip命令时应该自动安装这个库。否则,可以先运行$ pip install zeep

开始

有以下选项可通过Web服务访问NetSuite帐户:

  • 通过登录传递凭据(电子邮件、密码、角色和帐户ID)并启动请求会话
  • 在每个请求的头中传递凭据
  • 使用基于令牌的身份验证(在每个请求中)

使用凭据登录

下面的代码执行netsuite帐户登录并启动web服务会话。

fromnetsuitesdkimportNetSuiteClient# Initialize the NetSuite client instance by passing the application Id# which will be passed to the request header in the login operation.ns=NetSuiteClient(caching='sqlite',debug=True)passport=ns.create_passport(email=NS_EMAIL,password=NS_PASSWORD,role=NS_ROLE,account=NS_ACCOUNT)# Authenticate the user and start a new webservice session in NetSuitens.login(app_id=NS_APPID,passport=passport)# Make requests. All requests done in this session will be identified# with the application Id passed to the login operationns.logout()

为了避免在python源代码文件中存储凭证,可以使用 python dotenv($ pip install python-dotenv)加载身份验证 作为环境变量的.env文件的凭据。.env文件的外观如下:

NS_EMAIL = '*****@example.com'
NS_PASSWORD = '*******'
NS_ROLE = '1047'
NS_ACCOUNT = '*********'
NS_APPID = '********-****-****-****-************'

变量可以加载如下:

importosfromdotenvimportload_dotenvload_dotenv()NS_EMAIL=os.getenv("NS_EMAIL")NS_PASSWORD=os.getenv("NS_PASSWORD")NS_ROLE=os.getenv("NS_ROLE")NS_ACCOUNT=os.getenv("NS_ACCOUNT")NS_APPID=os.getenv("NS_APPID")

关于认证的备注和可能的错误

注意:NetSuite要求对 所有NetSuite帐户中的所有管理员和其他高权限角色。 相反,您可以使用非高特权角色登录或使用 使用您的请求进行基于令牌的身份验证(TBA)。有关TBA,请参见下文。

如果登录失败,将引发NetSuite引擎错误。

有关NetSuite身份验证的详细信息,请参阅: (https://docs.oracle.com/cloud/latest/netsuitecs_gs/NSATH/NSATH.pdf

通过请求传递凭证

待定

基于令牌的身份验证

待定

获取请求

一个基本的例子(ns是对一个NetSuiteClient实例的引用):

vendor=ns.get('vendor',internalId=ref.internalId)ns.print_values(vendor)

搜索

要执行搜索请求,请使用NetSuite.search。 sdk提供了一些实用功能/类:

  • basic_stringfield_search:一个基本的例子(ns是对一个NetSuiteClient实例的引用):
records=ns.basic_stringfield_search(type_name='Vendor',attribute='entityId',value='Alexander Valley Vineyards',operator='is')print(records[0].internalId)
  • PaginatedSearch(在utils.py中): 它的用法可以在实用函数NetSuiteClient.paginated_search
  • 中看到。

upsert

基本示例(ns是对一个NetSuiteClient实例的引用):

vendor=ns.Vendor()vendor.externalId='test_vendor'vendor.companyName='Another Test Inc.'ref=ns.upsert(record=vendor)

上游列表

基本示例(ns是对一个NetSuiteClient实例的引用):

customer1=ns.Customer(externalId='customer',email='test1@example.com')customer2=ns.Customer(externalId='another_customer',email='test2@example.com')ns.upsertList(records=[customer1,customer2])

文档

文档可以在docs/\u build/html文件夹(open index.html)中找到,很快就会在readthedocs中找到。 对于贡献者:构建文档(cd to/docs and)运行make buildapi 以及make html

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何使用泛型在Java中生成通用方法?   java从ISO/IEC 197944图像数据文件创建图像   java实现RSA的代码有什么问题?   javascript如何将JsonArray从解析云检索到安卓?   在vaadin中上传和下载java文件   java ListView自定义适配器OnClick启动URL链接   java在一个hbox中提供两个元素的独立对齐   java用类名创建类   java从unix命令行运行jar文件   java FTP下载在文件#146处停止