Overview
Counterparts represent the suppliers and clients of an organization. They can be organizations or individuals. A counterpart must be created before an organization can create invoices, quotes, and other documents.Roles and permissions
To use the/counterparts* endpoints with an organization user token, this organization user must have a role with the counterpart permission.
If using a partner-level token, no special permissions are needed.
Create a counterpart
To create a new counterpart, callPOST /counterparts with the request body containing the name, address, contact information, and other details.
- Organization
- Individual
language field in the payload of the POST /counterparts request determines the language on all PDF documents for the counterpart. If the counterpart language is not provided, Tesouro checks whether or not the organization’s settings object contains a default language and creates PDF documents in that language. If neither is available, all PDF documents for the counterpart will be in English.
The successful response contains the unique id assigned to this counterpart, along with other information.
- Addresses, contacts - required to issue invoices to this counterpart.
- Bank accounts - required to make bank-to-bank payments to this counterpart.
Counterpart address
Theaddress specified when creating a counterpart becomes its default billing address for invoices.
The ID of this address is saved to the default_billing_address_id field of the counterpart object.
If you add additional addresses to a counterpart, you can change its default billing address at any time by calling PATCH /counterparts/{counterpart_id}.
Counterpart tax ID
This information applies to accounts receivable.
Tax ID examples
- For organizations,
tax_idcan be the taxpayer number or a similar business identifier. - For individuals,
tax_idcan be a government-issued identification number such as a social security number (SSN), taxpayer number, passport number, national ID, or similar.
Check if tax ID is required
Tesouro API follows these conventions:- Organization-type counterparts require at least one tax ID specified.
- Individual-type counterparts generally do not require a tax ID.
GET /receivables/required-fields to check whether tax_id is required for organization-type or individual-type counterparts from a specific country. (In the example below, spaces are added for readability.)
tax_id filled in, you can instead use:
tax_id is required for said counterpart:
Counterpart auto-linking and auto-creation
Auto-linking
Every time a payable is created via OCR, updated, or approved for payment, Tesouro OCR checks if thecounterpart_id is present in the payable. In case the counterpart_id is null, Tesouro uses the other counterpart information found in the payable to perform a search in the organization’s database on this sequence:
- Tax ID (
tax_idfield) - Exact name AND address (
city,country,postal_code, andline1fields)
counterpart_id remains as null.
If a unique counterpart register is found in the organization’s database, i.e. this counterpart already exists in the Tesouro system, the payable is then automatically linked to the counterpart found, avoiding any manual work. Tesouro also tries to enrich the counterpart register in the database with the supplied counterpart data.
In this case, the counterpart’s is_vendor field is set to true to indicate that this counterpart appears in payables.
AI-Powered counterpart suggestionsWhen a user uploads a payable, Tesouro automatically analyzes the payable data and uses AI to suggest the most likely matching counterpart. The suggestion is based on the similarity of the following fields:
nameaddressbank_account
GET /payables/{payable_id}/suggestions.Auto-creation
When a payable is moved to thepaid, partially_paid, or waiting_for_approval statuses, Tesouro also tries the counterpart auto-linking.
If the counterpart cannot be auto-linked, a new counterpart will be automatically created with the information provided in the payable. The counterpart sub-resources are also created.
In this case, the is_vendor field is set to true to indicate that this counterpart appears in payables.
If the payable does not have enough information about the counterpart for its auto-creation, the counterpart cannot be created nor linked to the payable.
The auto-creation occurs only when the payable is submitted for
approval,
approved, marked as
partially or
completely paid. Before this
point, users are able to update the payable and new data for the auto-linking may
be provided. Therefore, auto-creation is the final step before freezing the payable data.
Sub-resources
The counterparts sub-resources, which are addresses and bank accounts, can also be set during the auto-creation process, following this logic:- If no sub-resource information is found in the payable but the counterpart already exists in the Tesouro system, Tesouro fills the payable with the sub-resource information stored in the Tesouro system (the default register, when applicable).
- If the sub-resource information is found in the payable, Tesouro checks if this information already exists in the Tesouro system:
- If the sub-resource information is found in the payable but is not present in the Tesouro system, Tesouro automatically creates these counterpart sub-resources in the Tesouro system, if the mandatory fields are provided.
- If the payable does not have enough information about the counterpart sub-resources for their auto-creation, the counterpart cannot be created nor linked to the payable.
How to enable auto-linking and auto-creation
The auto-linking and auto-creation features are disabled by default.
allow_counterpart_autolinking and allow_counterpart_autocreation respectively.
To enable or disable the auto-linking or the auto-creation, send a PATCH request to the /settings endpoint:
Retrieve a counterpart
To get information about a specific counterpart, callGET /counterparts/{counterpart_id} as shown:
counterpart_id provided.
List all counterparts
To get a list of all of an organization’s counterparts, callGET /counterparts as shown:
Sort and filter counterparts
You can sort the returned counterparts by name, and filter the results by ID, name, address, email address, and other fields. For a list of available sort and filter parameters, see the description of theGET /counterparts endpoint. Here are some filtering examples:
GET /counterparts?type=organization&sort=counterpart_name- get the counterparts that are organizations, sorted by name.GET /counterparts?counterpart_name__icontains=net- get all counterparts whose name contains “net” (case-insensitive).GET /counterparts?address.country=US- get all counterparts registered in the United States (theaddress.countryparameter is a two-letter country code).GET /counterparts?created_at__gte=2022-01-01T00%3A00%3A00- get all counterparts created on or after January 1, 2022.
Edit a counterpart
To edit an existing counterpart, callPATCH /counterparts/{counterpart_id}:
language field of a counterpart will also update the language on all PDF documents created for that counterpart.
All
PATCH requests to the endpoint must include the counterpart’s type object in the request
body. You must provide an empty object if there is no data to be updated within the counterpart
type object. For example, the following snippet updates the counterpart’s
default_shipping_address_id and default_billing_address_id fields:Delete a counterpart
To delete an existing counterpart, callDELETE /counterparts/{counterpart_id}: