Invalid XML Error Missing 'Type' Element when Executing API Request in Twinfield

88 Views Asked by At

I'm encountering an issue while attempting to execute a request on the Twinfield API. The purpose of my code is to perform a browse operation using the API, but I keep receiving an error message indicating an "Invalid XML - element 'type' missing." It's weird because I have put the type element in my request. Here's the Python code snippet I'm running:

def browseTest(sleutel):
    soap_env2 = f"""
    <soap:Envelope xmlns:soap="example_link_1" xmlns:xsi="example_link_2" xmlns:xsd="example_link_3">
        <soap:Header>
            <Header xmlns="http://www.twinfield.com/">
                <AccessToken>{sleutel}</AccessToken>
                <CompanyCode>2000100</CompanyCode>
            </Header>
        </soap:Header>
        <soap:Body>
            <ProcessXmlDocument xmlns="http://www.twinfield.com/">
                <xmlRequest>
                    <read>
                        <type>browse</type>
                        <office>2000100</office>
                        <code>000</code>
                    </read>
                </xmlRequest>
            </ProcessXmlDocument>
        </soap:Body>
    </soap:Envelope>
    """
    headers = {
    'Content-Type': 'text/xml'
    }
    response = requests.request("POST", "example link", headers=headers, data=soap_env2)
    print(response)

The response I receive from the request is as follows:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="example_link_4" xmlns:xsi="example_link_5" xmlns:xsd="example_link_6">
    <soap:Body>
        <ProcessXmlDocumentResponse xmlns="http://www.twinfield.com/">
            <ProcessXmlDocumentResult>
                <read msgtype="error" msg="Invalid XML - element 'type' missing." result="0">
                    <type>browse</type>
                    <office>2000000</office>
                    <code>000</code>
                </read>
            </ProcessXmlDocumentResult>
        </ProcessXmlDocumentResponse>
    </soap:Body>
</soap:Envelope>

I'm seeking assistance to understand why this error occurs and how I can fix it. It seems that the 'type' element within the 'read' tag is missing in my XML request. I have verified the structure of my XML against the Twinfield API documentation, and it appears to be correct. But I'm not because of the error. I must mention, I do get a 200 code with the response but the text that I get back has got the error message. What could be causing this issue, and how can I ensure that the 'type' element is included in my XML request? Any insights or suggestions would be greatly appreciated. Thank you! I tried changing up where to place the type element but that did not work. It gave me the 500 code and it made the XML code unreadable.

0

There are 0 best solutions below