简体   繁体   中英

Simple Twinfield API request with Postman

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!

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标题设置

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM