我想从我的 Python 脚本中将日记条目发布到 Netsuite。我正在使用 zeep 与 SuiteTalk 交谈。
我是 Netsuite 的新手,我是 SOAP 的新手。在互联网示例之后,我设法使用以下代码通过 Python 脚本添加了一个测试客户:
def make_app_info(client):
AppInfo = client.get_type('ns4:ApplicationInfo')
app_info = AppInfo(applicationId=NS_APPID)
return app_info
def make_passport(client):
RecordRef = client.get_type('ns0:RecordRef')
Passport = client.get_type('ns0:Passport')
role = RecordRef(internalId=NS_ROLE)
return Passport(email=NS_EMAIL,
password=NS_PASSWORD,
account=NS_ACCOUNT,
role=role)
def login_client():
client = Client(WSDL_URL)
login = client.service.login(passport=make_passport(client), _soapheaders={'applicationInfo': make_app_info(client)})
return client
WSDL_URL
我正在使用的是https://webservices.netsuite.com/wsdl/v2017_2_0/netsuite.wsdl
使用上面的客户端,下面的代码添加了客户:
def add_customer():
client = login_client()
Customer = client.get_type('ns13:Customer')
customer = Customer(
lastName='Prasad',
firstName='Vikas',
email='vikasprasad@example.com',
companyName='Test Company'
)
client.service.add(customer)
add_customer()
以上Customer
成功添加到 Netsuite 帐户,我可以在 webapp 的列表中看到它。继续上面的例子,我写了这段代码来添加JournalEntry
:
def get_record_by_type(client, type, internal_id):
RecordRef = client.get_type('ns0:RecordRef')
record = RecordRef(internalId=internal_id, type=type)
response = client.service.get(record,
_soapheaders={
'applicationInfo': make_app_info(client),
'passport': make_passport(client),
}
)
r = response.body.readResponse
if r.status.isSuccess:
return r.record
def add_journal_entry():
client = login_client()
# get subsidiary by internal id
subsidiary = get_record_by_type(client, 'subsidiary', '1')
print(subsidiary) # This prints a valid subsidiary having internal id 1
# create two journal entry lines
JournalEntryLine = client.get_type('ns31:JournalEntryLine')
credit_line = JournalEntryLine(account=get_record_by_type(client, 'account', '1'), credit=100)
debit_line = JournalEntryLine(account=get_record_by_type(client, 'account', '2'), debit=100)
print(credit_line) # This prints credit_line with a valid account having internal id 1
print(debit_line) # This prints debit_line with a valid account having internal id 2
JournalEntryLineList = client.get_type('ns31:JournalEntryLineList')
journal_entry_line_list = JournalEntryLineList(line=[credit_line, debit_line])
JournalEntry = client.get_type('ns31:JournalEntry')
journal_entry = JournalEntry(subsidiary=subsidiary, lineList=journal_entry_line_list)
client.service.add(journal_entry, _soapheaders={'passport': make_passport(client),
'applicationInfo': make_app_info(client)}) # Fails on this line.
add_journal_entry()
这在调用中失败并client.service.add(...)
出现错误:
zeep.exceptions.Fault:org.xml.sax.SAXException:预期 {urn:core_2017_2.platform.webservices.netsuite.com} 名称,找到 {urn:accounting_2017_2.lists.webservices.netsuite.com} 名称
我确信这在 SOAP 世界中很愚蠢,但我不确定要调试到哪个方向。为什么预期的和找到的有区别?我没有提到任何特定的命名空间。它只是 WSDL v2017_2_0
,所有的client.get_type()
调用都是在此之上进行的。这个错误来自哪里?
在 Netsuite 用户组问过同样的问题: https ://usergroup.netsuite.com/users/forum/platform-areas/web-services-suitetalk/434717-netsuite-namespace-conflict#post434717
更新:
根据@Justin W 的回答,事实证明,我可以直接告诉 Suitetalk和使用 a和 Suitetalk 将了解使用什么和s ,而不是从 Suitetalk 获取subsidiary
and account
sinternalId
然后将它们添加到请求中.type
internalId
RecordRef
subsidiary
account
即subsidiary = get_record_by_type(client, 'subsidiary', '1')
可以更改为subsidiary = RecordRef(internalId='1', type='subsidiary')
相似地
credit_line = JournalEntryLine(account=get_record_by_type(client, 'account', '1'), credit=100)
debit_line = JournalEntryLine(account=get_record_by_type(client, 'account', '2'), debit=100)
可以改为
credit_line = JournalEntryLine(account=RecordRef(internalId='1', type='account'), credit=100)
debit_line = JournalEntryLine(account=RecordRef(internalId='2', type='account'), debit=100)