To create a contract the technical user needs the permission Contracts → Create (Contracts → Read to read them). To read contract types you need Contracts → Read, for durations Invoices → Read. Roles are assigned as in How to create a role and a user; the technical user and the key are in Technical users and API keys: connecting an integration.
The endpoint for contracts and transits is:
/rest/v1/contract
Bookings, quotes, contracts and transits are all created using the same endpoint: it is the parameters that determine the type of document created.
Creating a new contract/transit
POST /rest/v1/contract
{
"contractor1_id": 1,
"contractor2_id": 123,
"type_id": 10,
"duration_id": 11,
"date": "2022-04-14",
"date_start": "2022-06-01",
"date_end": "2022-06-07",
"vector_id": 456
}The required fields are these (vector_id is optional but usually needed):
contractor1_id: the ID of the marina's own customer record; for almost all marinas it is 1.
contractor2_id: the ID of the customer.
type_id, duration_id: the IDs are read with GET /rest/v1/contractType and GET /rest/v1/contractDuration; they vary from marina to marina.
date: the date of the contract.
date_start: the occupation start date.
date_end: the occupation end date.
vector_id: the ID of the boat to link to the contract (optional).
date_quote_valid_until: the validity date, required when the chosen type is a quote.
If the chosen type and duration are not a pair your marina allows, the call answers 400 with the list of errors.
This call only creates the document: it does not assign a berth and does not add the price lines.
Workflow to create a new contract, transit, booking or quote
To create a new contract, transit, booking or quote from scratch, the sequence is the following:
Check whether the customer already exists, using the e-mail as the search parameter (field
cliente_email, see Customers API); if it does not exist, create a new one.Check whether the boat already exists: with the filter on
barca_proprietarioand onbarca_targa(orbarca_nome), as in Vessels and vehicles API; if it does not exist, create a new one (to create it with the right type, see the Vessel types API).Create the new item with the APIs on this page.
