This example shows how to create a new contact, complete with addresses and a referenced company. Let’s see the necessary steps:
- create an organization contact
- create the organizations contacts postal address
- create the organizations contacts phone number
- create the organization itself
- finish creation of the organization contact
- create the contact we initially wanted (this time a person)
- create the contacts email
- create the contacts phone number
- finish
Create an organization contact #
Organization objects are used to organize contact entries like folders in a file system. They are not contacts themself, instead they need a primary main contact representing an entry in your address book. Let’s create that contact first:
// POST api/contact
{
"active": true,
"person": false,
"lastname": "5 Point AG",
"description": "Zentrale der 5Point. Das hier ist ein Kontakt den wir als Firmenadresse benutzen möchten. Als nächstes müssen wir noch eine Post-Adresse für diesen Kontakt hinterlegen."
}
Create the organization contacts postal address #
As you may noticed, this contact has no fields to enter phone numbers or email addresses. They are its own entity, because a contact is not limited to a certain number of addresses. We can POST as many of them as we want:
// POST api/contactfield
{
"value": ";;Rheinstraße 40-42;Darmstadt;;64283;Deutschland",
"customlabel": null,
"type": "ADR",
"subtype": "WORK",
"contact": {{contactCreated}}
}
Create the organization contacts phone number #
// TODO PUT /api/contactfield to create phone number
Create the organization itself #
The addresses are created now. They are linked to the contact we also created. Two steps are left to finish up the organization. We can create the organization now:
// POST api/organization
{
"name": "5Point",
"description": "This is an demo organization created via API. Internal its called '5Point'. The 'official' name is stored in the address contact object",
"address": {{contactCreated}}
}
Finish creation of the organization #
We have to connect some „loose ends“: the organizations contact has to be updated with references to its organization as well to its preferred addresses:
// PUT api/contact/{{contactCreated}}
{
"active": true,
"person": false,
"lastname": "5 Point AG",
"description": "Zentrale der 5Point",
"exportId": "avl-adr-001",
"mainAddress" : {{contactfieldCreated}},
"organization": {{organizationCreated}}
}
Create a real contact now #
That was a lot of steps. But lets say, we want to create a contact (a person this time) to an already existing organization. If we just hava a name, this can be a single POST.
// POST api/contact
{
"active": true,
"person": true,
"firstname": "Christoph",
"lastname": "Preisser",
"description": "Entwicklungsleiter 5P. Als bevorzugte Postadresse nehmen wir die, die wir schon für die Organisation erstellt haben.",
"mainAddress" : {{contactfieldCreated}},
"organization": {{organizationCreated}}
}
You may have noticed, we used the existing companys address as preferred postal address. This way, if the companys address is changed, it will affect the work-address of this contact also. We can do this for telephone and email also, but maybe we have dedicated addresses we want to use. The we have to add them like before.
Add more addresses #
// TODO PUT /api/contactfield for email
// TODO PUT /api/contactfield for phone
Finish #
// TODO PUT /api/contact to update mainAddresses