问题
I want to post a journal entry to Netsuite from my Python script. I am using zeep to talk to SuiteTalk.
I am new to Netsuite and I am new to SOAP. Following on internet examples, I managed to add a test customer via Python script using the below code:
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
The WSDL_URL
I am using is https://webservices.netsuite.com/wsdl/v2017_2_0/netsuite.wsdl
Using the above client the below code adds the customer:
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()
The above adds the Customer
successfully to the Netsuite account and I can see it in the list on the webapp.
Continuing on the above example, I wrote this code to add 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()
This fails on the call client.service.add(...)
with the error:
zeep.exceptions.Fault: org.xml.sax.SAXException: Expected {urn:core_2017_2.platform.webservices.netsuite.com}name, found {urn:accounting_2017_2.lists.webservices.netsuite.com}name
I am sure this is something silly in the world of SOAP, but I am not sure which direction to debug into. Why is there a difference between the expected and the found one? I have nowhere mentioned any specific namespaces. Its just WSDL v2017_2_0
and all the client.get_type()
call are made on top of this. Where is this error coming from?
Have asked the same question at Netsuite user group: https://usergroup.netsuite.com/users/forum/platform-areas/web-services-suitetalk/434717-netsuite-namespace-conflict#post434717
UPDATE:
Based on @Justin W's answer it turns out, that instead of fetching the subsidiary
and account
s by their internalId
from Suitetalk and then adding them in the request, I can directly tell Suitetalk the type
and the internalId
using a RecordRef
and Suitetalk will understand what subsidiary
and account
s to use.
i.e. subsidiary = get_record_by_type(client, 'subsidiary', '1')
can be changed to subsidiary = RecordRef(internalId='1', type='subsidiary')
Similarly
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)
can be changed to
credit_line = JournalEntryLine(account=RecordRef(internalId='1', type='account'), credit=100)
debit_line = JournalEntryLine(account=RecordRef(internalId='2', type='account'), debit=100)
回答1:
I think it's probably that your get_account()
returns an Account
but JournalEntryLine.account
is supposed to be a RecordRef
(actually, the same problem for get_subsidiary()
as well)
来源:https://stackoverflow.com/questions/50461876/netsuite-namespace-conflict-core-2017-2-platform-vs-accounting-2017-2-lists