This article is part of the article serie
Setting up OAuth 2.0 - IntroductionYou can import data into Twinfield or extract data from Twinfield by posting an request. Twinfield will only accept your request if you send along a valid access token. If you don't have one please refer to the previous step:
Request an access tokenTwinfield has multiple clusters to which you can post an request. Each end user is assigned to a specific cluster. Posting to the wrong cluster will result in an error. Please read this article to determine which cluster you need:
Which cluster do I need for my request?To send an request you need to send a POST request to one of Twinfield's endpoints. The endpoints looks like this:
https://
clusterUrl/webservices/processxml.asmx
Important: Replace the red part of the endpoint by the twf.clusterUrl. Please refer to this article:
Which cluster do I need for my request?Important: In the link above you see webservices/. Behind the / is processxml.asmx. There are multiple endpoints that you can use. Each endpoint has its own name after the /. In this article you'll find an overview of the three types of web services that are available and a list of all the available endpoints:
Which types of web services are available?Use the table below for the headers that you need to send along in your POST request.
Header__________ | Value |
---|
Content-Type | text/xml |
SOAPAction | You can find a complete overview of how to use the endpoint by adding ?wsdl to the end of the url of the endpoint. For example: https://accounting2.twinfield.com/webservices/periodservice.svc?wsdl Search for "soapaction" on the wsdl-page to find the value you need. |
In the body of your POST request you can add a soap enveloppe that contains your request.
Important: The xml tags are case sensitive.
A blank soap envelope looks like this. Note that we declare the xmlns for the soap envelope itself and for the request to Twinfield.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:twinfield="http://www.twinfield.com/"> <soap:Header> ... </soap:Header> <soap:Body> ... </soap:Body> </soap:Envelope> |
The next step is to fill the <soap:Header>. How you need to fill it depends on the type of webservice that you're using. For the XML Web Services you'll need to use <twinfield:Header>.
<soap:Header> <twinfield:Header> ... </twinfield:Header> </soap:Header> |
For the Command & Query Web Services you'll need to use <twinfield:Authentication>.
<soap:Header> <twinfield:Authentication> ... </twinfield:Authentication> </soap:Header> |
What all webservices have in common is that you need to use <twinfield:AccessToken> and <twinfield:CompanyCode> within both <twinfield:Header> and <twinfield:Authentication>. In the code snippet below we show you <twinfield:Header> but it works the same for <twinfield:Authentication>.
<soap:Header> <twinfield:Header> <twinfield:AccessToken>7c944a6b#####7296a98</twinfield:AccessToken> <twinfield:CompanyCode>123456</twinfield:CompanyCode> </twinfield:Header> </soap:Header> |
Important: You must always send <twinfield:AccessToken> along in your soap envelope, but it depends on the situation if you need to send <twinfield:CompanyCode>. Sometimes you must add it and other times you must leave it out. Use the table below for a reference.
Situation____________ | Do you need to send <twinfield:CompanyCode>? |
---|
You want to retrieve a list of all companies that exist in an organization | Omit the tag <twinfield:CompanyCode>. Good to know: Refer to this article to request a list of all companies in an organization: https://accounting.twinfield.com/webservices/documentation/#/ApiReference/Masters/Offices |
You want to send an request for specific company | Add <twinfield:CompanyCode> and mention the company code. |
You want to send an request for multiple companies | Only add <twinfield:CompanyCode> for the first company code. |
Now that you got a basic soap envelope you can continue to the next step. This is adding content in the soap body. Use this article for this:
Which types of web services are available?