我想从我的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}名称 {瓮: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,而不是从Suitetalk的subsidiary
获取account
和internalId
,然后在请求中添加它们。使用type
和Suitetalk的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)
答案 0 :(得分:1)
我认为您的Account
可能会返回JournalEntryLine.account
但RecordRef
应该是get_subsidiary()
(实际上sed
的问题与$ cat > foo
this
that
$ sed 's/$/__/g' foo
this__
that__
$ sed 's/$/__/g' foo | hexdump -C
00000000 74 68 69 73 5f 5f 0a 74 68 61 74 5f 5f 0a |this__.that__.|
相同孔)