Netsuite命名空间冲突(core_2017_2.platform vs accounting_2017_2.lists)

2024-10-03 11:19:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从Python脚本向Netsuite发布日志条目。我用zeep和SuiteTalk通话。在

我不熟悉Netsuite,也不熟悉SOAP。下面是internet示例,我使用以下代码通过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_URLhttps://webservices.netsuite.com/wsdl/v2017_2_0/netsuite.wsdl

使用上述客户机,以下代码将添加客户机:

^{pr2}$

上面的操作成功地将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: Expected {urn:core_2017_2.platform.webservices.netsuite.com}name, found {urn:accounting_2017_2.lists.webservices.netsuite.com}name

我确信这在SOAP的世界里是很愚蠢的,但是我不确定要调试到哪个方向。为什么期望值和发现值有区别?我没有提到任何特定的名称空间。它只是WSDLv2017_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使用subsidiary和{},而不是通过它们的internalId从Suitetalk中获取它们,然后将它们添加到请求中,我可以直接告诉Suitetalk使用RecordRef和{}使用{}和{}。在

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)

Tags: clientgetmakebytypeservicelineaccount