0

I want to connect sales invoices with javascript/ google apps script. Therefore I want to test some things with Postman. I know, that the API works with XML and to get data you need to use the so called Browse code 100. But I am stucked with creating a working request to get sales invoice data :(

What I did so far:

  • Read the Twinfield API documentation
  • Created a login in the developer portal
  • Managed to request authorization code with Postman: I did a workaround to adjust the parameters in Postman and then paste the request URL into the browser
  • Managed to request access token
  • Determine cluster

I did a lot of research but couldn't find any examples I could understand. Examples like

  • how should a request URL in Postman look like
  • what parameters do I need
  • is it possible to have a handy request in javascript to get open sales invoices

I would be very grateful for any help!

kim
  • 3
  • 2

1 Answers1

1

Try this

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Header>
        <Header xmlns="http://www.twinfield.com/">
            <AccessToken>{{Accescode}}</AccessToken>
            <CompanyCode>{{Company}}</CompanyCode>
        </Header>
    </soap:Header>
    <soap:Body>
        <ProcessXmlDocument xmlns="http://www.twinfield.com/">
            <xmlRequest>
                <columns code="100">
                    <column xmlns="">
                        <field>fin.trs.head.yearperiod</field>
                        <operator>between</operator>
                        <from>2021/01</from>
                        <to>2022/01</to>
                        <visible>true</visible>
                    </column>
                    <column xmlns="">
                        <field>fin.trs.head.code</field>
                        <visible>true</visible>
                    </column>
                    <column xmlns="">
                        <field>fin.trs.head.shortname</field>
                        <visible>true</visible>
                    </column>
                    <column xmlns="">
                        <field>fin.trs.head.number</field>
                        <visible>true</visible>
                    </column>
                    <column xmlns="">
                        <field>fin.trs.head.status</field>
                        <visible>true</visible>
                    </column>
                    <column xmlns="">
                        <field>fin.trs.head.date</field>
                        <visible>true</visible>
                    </column>
                    <column xmlns="">
                        <field>fin.trs.line.dim2</field>
                        <visible>true</visible>
                    </column>
                    <column xmlns="">
                        <field>fin.trs.line.dim2name</field>
                        <visible>true</visible>
                    </column>
                    <column xmlns="">
                        <field>fin.trs.head.curcode</field>
                        <visible>true</visible>
                    </column>
                    <column xmlns="">
                        <field>fin.trs.line.valuesigned</field>
                        <visible>true</visible>
                    </column>
                    <column xmlns="">
                        <field>fin.trs.line.basevaluesigned</field>
                        <visible>true</visible>
                    </column>
                    <column xmlns="">
                        <field>fin.trs.line.repvaluesigned</field>
                        <visible>true</visible>
                    </column>
                    <column xmlns="">
                        <field>fin.trs.line.openbasevaluesigned</field>
                        <visible>true</visible>
                    </column>
                    <column xmlns="">
                        <field>fin.trs.line.invnumber</field>
                        <visible>true</visible>
                    </column>
                    <column xmlns="">
                        <field>fin.trs.line.datedue</field>
                        <visible>true</visible>
                    </column>
                    <column xmlns="">
                        <field>fin.trs.line.matchstatus</field>
                        <visible>true</visible>
                    </column>
                    <column xmlns="">
                        <field>fin.trs.line.matchnumber</field>
                        <visible>true</visible>
                    </column>
                    <column xmlns="">
                        <field>fin.trs.line.matchdate</field>
                        <visible>true</visible>
                    </column>
                    <column xmlns="">
                        <field>fin.trs.line.openvaluesigned</field>
                        <visible>true</visible>
                    </column>
                    <column xmlns="">
                        <field>fin.trs.line.availableforpayruns</field>
                        <visible>true</visible>
                    </column>
                    <column xmlns="">
                        <field>fin.trs.line.modified</field>
                        <visible>true</visible>
                    </column>
                </columns>
            </xmlRequest>
        </ProcessXmlDocument>
    </soap:Body>
</soap:Envelope>

EDIT: Lets start with the beginning, first I'm assuming you are able to get the access code. With the access code you need to do a Postmand get request to the following url: https://login.twinfield.com/auth/authentication/connect/accesstokenvalidation?token={{Accescode}}

from the results you need to copy over the clusterUrl for me it looks like this:

"twf.clusterUrl": "https://api.accounting2.twinfield.com"

Next we need to find the companyID's this is also something we can get from Postman with the following post to the url: https://api.accounting2.twinfield.com/webservices/processxml.asmx?wsdl

as you can see this has the cluserURL from before so you've to replace this with the one you find. The XML envelope you need to send with this request is the following:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:twin="http://www.twinfield.com/">
    <soapenv:Header>
        <twin:Header>
            <twin:AccessToken>{{Accescode}}</twin:AccessToken>
        </twin:Header>
    </soapenv:Header>
    <soapenv:Body>
        <twin:ProcessXmlString>
            <twin:xmlRequest><![CDATA[<list><type>offices</type></list>]]></twin:xmlRequest>
        </twin:ProcessXmlString>
    </soapenv:Body>
</soapenv:Envelope>

this will result in a list with ID's you can collect the data from. To get the sales invoices you need to use the following url again:

https://api.accounting2.twinfield.com/webservices/processxml.asmx?wsdl

but this time we change the envelope to the first one I posted above, just the whole thing into the raw body, this should result in a list of invoices.

if you need more info I can try to get a collection working for you but I hope this will help enough to get you started

Edit 2: Regarding your second question, you need to set the header to accept the xml input, see below header settings

Tjaym
  • 77
  • 7
  • Thank you! Is the CompanyCode the same as the organisationId? If not, where can I find the Company code? And what kind of request URL should I put into postman? Or how can I test your xml request? Sorry for those questions, but I am completely new to this :( – kim Jun 09 '22 at 12:43
  • No worries, everyone has to start somewhere. I've edited my post to get a more complete answer for you. I hope this will help you more then my first answer. Please let me know if you need more info :) – Tjaym Jun 09 '22 at 14:47
  • Thank you so much for your patience and for editing your answer!!! I now can understand it better! But when I make the POST request in postman with the url (for me it's https://api.accounting.twinfield.com/webservices/processxml.asmx?wsdl) and the envelop you posted, I get this error: "The server cannot service the request because the media type is unsupported." Do you maybe know what could cause this error? – kim Jun 13 '22 at 12:00
  • A small adjustment should fix this, you will need to set the header to accept the xml input, see the screenshot I've added to the answer – Tjaym Jun 13 '22 at 12:16