Créer et modifier un particulier
Pour un explication de la hiérarchie, consulter la page Présentation de la rubrique Contacts
Mettre à jour ses données "primaires"
données "primaires" des Person
parameters:
- $ref: "#/components/parameters/appId"
- name: id
in: path
description: "ID of a person"
required: true
schema:
type: integer
- name: civility
in: query
description: "Civility is the lastname prefix"
schema:
type: string
nullable: true
- name: lastname
in: query
schema:
type: string
- name: firstname
in: query
schema:
type: string
- name: picture
in: query
schema:
oneOf:
- type: string
format: byte
- type: string
format: uri
- name: metadata
in: query
schema:
type: array
nullable: true
requête de create
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer <token>");
var app_id = 1; // votre app id
var contact_types = "persons" // type de contact organizations | persons
var name = "New Sinao";
var billingName = "NEW SINAO"
// voir le YAML ci-dessus pour tous les paramètres
var request_params = `name=${name}&billing_name=${billingName}`;
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch(`https://api.sinao.app/v1/apps/${app_id}/${contact_types}?${request_params}`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
requête d'update :
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer <token>");
var app_id = 1; // votre app id
var contact_types = "persons" // type de contact organizations | persons
var contact_id = 27844;
var new_name = "New Sinao";
var new_billingName = "NEW SINAO"
var request_params = `name=${new_name}&billing_name=${new_billingName}`;
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch(`https://api.sinao.app/v1/apps/${app_id}/${contact_types}/${contact_id}/?${request_params}`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
// Voir un exemple de réponse dans la création d'entreprise
Créer des données "expanded" (ses liaisons)
Créer un nouvel établissement à un contact avec sa Place
2 destinataires EstablishmentContact
.
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer <token>");
var app_id = 1; // votre app id
var contact_types = "persons" // type de contact organizations | persons
var contact_id = 27844;
const new_place = {
"postal_code" : "38100",
"locality": "Grenoble",
"route": "5 place Nelson Mandela",
"country": "France"
};
const contact_one = {
"name" : "Dev 1",
"job": "developpeur",
"email": "[email protected]"
};
const contact_two = {
"name" : "Dev 2",
"job": "developpeur",
"email": "[email protected]"
};
// prepare request params
let request_params = `establishments[0][place][postal_code]=${new_place.postal_code}\
&establishments[0][place][locality]=${new_place.locality}\
&establishments[0][place][route]=${new_place.route}\
&establishments[0][place][country]=${new_place.country}\
&establishments[0][contacts][0][name]=${contact_one.name}\
&establishments[0][contacts][0][job]=${contact_one.job}\
&establishments[0][contacts][0][email]=${contact_one.email}\
&establishments[0][contacts][1][name]=${contact_two.name}\
&establishments[0][contacts][1][job]=${contact_two.job}\
&establishments[0][contacts][1][email]=${contact_two.email}\
`;
// pour obtenir le résultat avec les etablissement et leurs contacts dans la réponse : ajouter les expand
request_params += "&expand[]=establishments&expand[]=establishments.contacts"
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch(`https://api.sinao.app/v1/apps/${app_id}/${contact_types}/${contact_id}/?${request_params}`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
// Note : la réponse correspond à une entreprise, la reponse d'un particulier sera de la même forme
// avec bien sur les champs du YAML au lieu de ceux-ci
{
"id": 27844,
"name": "New Sinao",
"billing_name": "NEW SINAO",
"image": "/services/avatar/NewSinao/N",
"legal_form": "SAS",
"country_iso2": "FR",
"founding_date": "2015-04-26T22:00:00.000000Z",
"founding_location": null,
"dissolution_date": null,
"duns": null,
"national_id": "811340728",
"tax_id": null,
"vat_id": "FR32811340728",
"code_naf": "6201Z",
"number_of_employees": "1 ou 2 salariés",
"slogan": null,
"rcs": null,
"greffe": null,
"capital": null,
"vat_system": null,
"closeaccounting_period": null,
"deleted_at": null,
"created_at": "2022-07-15T05:39:49.000000Z",
"updated_at": "2023-10-24T10:23:01.000000Z",
"metadata": null,
"sirene_data": null,
"type": "organization",
"establishments": [
{
"id": 2227,
"name": null,
"emails": [],
"websites": null,
"phones": [],
"nic": null,
"is_headquarters": 0,
"is_favorite": null,
"details": null,
"created_at": "2023-10-24T14:09:48.000000Z",
"updated_at": "2023-10-24T14:09:48.000000Z",
"place": {
"id": 2033,
"latitude": null,
"longitude": null,
"street_number": null,
"route": "5 place Nelson Mandela",
"route2": null,
"locality": "Grenoble",
"sublocality": null,
"administrative_area_level_3": null,
"administrative_area_level_2": null,
"administrative_area_level_1": null,
"country": "France",
"countryiso2": null,
"postal_code": "38100",
"type": null,
"created_at": "2023-10-24T14:09:48.000000Z",
"updated_at": "2023-10-24T14:09:48.000000Z",
"formatted_address": " 5 place Nelson Mandela - 38100 Grenoble - France",
"short_postal_code": "38",
"exported_address": "5 place Nelson Mandela"
},
"contacts": [
{
"id": 427,
"name": "Dev 1",
"job": "developpeur",
"phone": null,
"email": "[email protected]"
},
{
"id": 428,
"name": "Dev 2",
"job": "developpeur",
"phone": null,
"email": "[email protected]"
}
]
},
{
"id": 1050,
"name": null,
"emails": [],
"websites": null,
"phones": [],
"nic": "00047",
"is_headquarters": 0,
"is_favorite": null,
"details": null,
"created_at": "2023-08-15T15:52:27.000000Z",
"updated_at": "2023-08-15T15:52:27.000000Z",
"place": {
"id": 862,
"latitude": "45.1769555",
"longitude": "5.7333869",
"street_number": "29",
"route": "Chemin de l'Église",
"route2": null,
"locality": "Grenoble",
"sublocality": null,
"administrative_area_level_3": null,
"administrative_area_level_2": "Isère",
"administrative_area_level_1": "Auvergne-Rhône-Alpes",
"country": "France",
"countryiso2": null,
"postal_code": "38100",
"type": null,
"created_at": "2023-08-15T15:52:27.000000Z",
"updated_at": "2023-08-15T15:52:27.000000Z",
"formatted_address": "29 Chemin de l'Église - 38100 Grenoble - France",
"short_postal_code": "38",
"exported_address": "29 Chemin de l'Église"
},
"contacts": [
{
"id": 408,
"name": "Contact2 Sinao",
"job": "Support",
"phone": "Secret",
"email": "contact2@Sinao"
}
]
}
]
}
Mettre à jour ses données "expanded" (ses liaisons)
Mettre à jour le nom de l'établissement que nous venons de créer.
Dans la réponse nous voyons que son id est 2227
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer <token>");
var app_id = 1; // votre app id
var contact_types = "persons" // type de contact organizations | persons
var contact_id = 27844;
const establishment_id = 2227;
// prepare request params
// préciser l'id de l'établissement
let request_params = `establishments[0][id]=${establishment_id}\
&establishments[0][name]=Bureau developpement`;
// pour obtenir le résultat avec les etablissement et leurs contacts dans la réponse : ajouter les expand
request_params += "&expand[]=establishments&expand[]=establishments.contacts"
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch(`https://api.sinao.app/v1/apps/${app_id}/${contact_types}/${contact_id}/?${request_params}`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
// Note : la réponse correspond à une entreprise, la reponse d'un particulier sera de la même forme
// avec bien sur les champs du YAML au lieu de ceux-ci
{
"id": 27844,
"name": "New Sinao",
"billing_name": "NEW SINAO",
"image": "/services/avatar/NewSinao/N",
"legal_form": "SAS",
"country_iso2": "FR",
"founding_date": "2015-04-26T22:00:00.000000Z",
"founding_location": null,
"dissolution_date": null,
"duns": null,
"national_id": "811340728",
"tax_id": null,
"vat_id": "FR32811340728",
"code_naf": "6201Z",
"number_of_employees": "1 ou 2 salariés",
"slogan": null,
"rcs": null,
"greffe": null,
"capital": null,
"vat_system": null,
"closeaccounting_period": null,
"deleted_at": null,
"created_at": "2022-07-15T05:39:49.000000Z",
"updated_at": "2023-10-24T10:23:01.000000Z",
"metadata": null,
"sirene_data": null,
"type": "organization",
"establishments": [
{
"id": 2227,
"name": "Bureau developpement",
"emails": [],
"websites": null,
"phones": [],
"nic": null,
"is_headquarters": 0,
"is_favorite": null,
"details": null,
"created_at": "2023-10-24T14:09:48.000000Z",
"updated_at": "2023-10-24T14:35:23.000000Z",
"place": {
"id": 2033,
"latitude": null,
"longitude": null,
"street_number": null,
"route": "5 place Nelson Mandela",
"route2": null,
"locality": "Grenoble",
"sublocality": null,
"administrative_area_level_3": null,
"administrative_area_level_2": null,
"administrative_area_level_1": null,
"country": "France",
"countryiso2": null,
"postal_code": "38100",
"type": null,
"created_at": "2023-10-24T14:09:48.000000Z",
"updated_at": "2023-10-24T14:09:48.000000Z",
"formatted_address": " 5 place Nelson Mandela - 38100 Grenoble - France",
"short_postal_code": "38",
"exported_address": "5 place Nelson Mandela"
},
"contacts": [
{
"id": 427,
"name": "Dev 1",
"job": "developpeur",
"phone": null,
"email": "[email protected]"
},
{
"id": 428,
"name": "Dev 2",
"job": "developpeur",
"phone": null,
"email": "[email protected]"
}
]
},
{
"id": 1050,
"name": null,
"emails": [],
"websites": null,
"phones": [],
"nic": "00047",
"is_headquarters": 0,
"is_favorite": null,
"details": null,
"created_at": "2023-08-15T15:52:27.000000Z",
"updated_at": "2023-08-15T15:52:27.000000Z",
"place": {
"id": 862,
"latitude": "45.1769555",
"longitude": "5.7333869",
"street_number": "29",
"route": "Chemin de l'Église",
"route2": null,
"locality": "Grenoble",
"sublocality": null,
"administrative_area_level_3": null,
"administrative_area_level_2": "Isère",
"administrative_area_level_1": "Auvergne-Rhône-Alpes",
"country": "France",
"countryiso2": null,
"postal_code": "38100",
"type": null,
"created_at": "2023-08-15T15:52:27.000000Z",
"updated_at": "2023-08-15T15:52:27.000000Z",
"formatted_address": "29 Chemin de l'Église - 38100 Grenoble - France",
"short_postal_code": "38",
"exported_address": "29 Chemin de l'Église"
},
"contacts": [
{
"id": 408,
"name": "Contact2 Sinao",
"job": "Support",
"phone": "Secret",
"email": "contact2@Sinao"
}
]
}
]
}
De le même manière, corrigeons le destinataire EstablishmentContact
id = 428, [email protected] n'existe pas.
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer <token>");
var app_id = 1; // votre app id
var contact_types = "persons" // type de contact organizations | persons
var contact_id = 27844;
const establishment_id = 2227;
const establishmentContact_id = 428
// prepare request params
// préciser l'id de l'établissement
let request_params = `establishments[0][id]=${establishment_id}\
&establishments[0][contacts][0][id]=${establishmentContact_id}
&establishments[0][contacts][0][name]=Contact Sinao
&establishments[0][contacts][0][email][email protected]`;
// pour obtenir le résultat avec les etablissement et leurs contacts dans la réponse : ajouter les expand
request_params += "&expand[]=establishments&expand[]=establishments.contacts"
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch(`https://api.sinao.app/v1/apps/${app_id}/${contact_types}/${contact_id}/?${request_params}`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
// Note : la réponse correspond à une entreprise, la reponse d'un particulier sera de la même forme
// avec bien sur les champs du YAML au lieu de ceux-ci
{
"id": 27844,
"name": "New Sinao",
"billing_name": "NEW SINAO",
"image": "/services/avatar/NewSinao/N",
"legal_form": "SAS",
"country_iso2": "FR",
"founding_date": "2015-04-26T22:00:00.000000Z",
"founding_location": null,
"dissolution_date": null,
"duns": null,
"national_id": "811340728",
"tax_id": null,
"vat_id": "FR32811340728",
"code_naf": "6201Z",
"number_of_employees": "1 ou 2 salariés",
"slogan": null,
"rcs": null,
"greffe": null,
"capital": null,
"vat_system": null,
"closeaccounting_period": null,
"deleted_at": null,
"created_at": "2022-07-15T05:39:49.000000Z",
"updated_at": "2023-10-24T10:23:01.000000Z",
"metadata": null,
"sirene_data": null,
"type": "organization",
"establishments": [
{
"id": 2227,
"name": "Bureau developpement",
"emails": [],
"websites": null,
"phones": [],
"nic": null,
"is_headquarters": 0,
"is_favorite": null,
"details": null,
"created_at": "2023-10-24T14:09:48.000000Z",
"updated_at": "2023-10-24T14:35:23.000000Z",
"place": {
"id": 2033,
"latitude": null,
"longitude": null,
"street_number": null,
"route": "5 place Nelson Mandela",
"route2": null,
"locality": "Grenoble",
"sublocality": null,
"administrative_area_level_3": null,
"administrative_area_level_2": null,
"administrative_area_level_1": null,
"country": "France",
"countryiso2": null,
"postal_code": "38100",
"type": null,
"created_at": "2023-10-24T14:09:48.000000Z",
"updated_at": "2023-10-24T14:09:48.000000Z",
"formatted_address": " 5 place Nelson Mandela - 38100 Grenoble - France",
"short_postal_code": "38",
"exported_address": "5 place Nelson Mandela"
},
"contacts": [
{
"id": 427,
"name": "Dev 1",
"job": "developpeur",
"phone": null,
"email": "[email protected]"
},
{
"id": 428,
"name": "Contact Sinao",
"job": "developpeur",
"phone": null,
"email": "[email protected]"
}
]
},
{
"id": 1050,
"name": null,
"emails": [],
"websites": null,
"phones": [],
"nic": "00047",
"is_headquarters": 0,
"is_favorite": null,
"details": null,
"created_at": "2023-08-15T15:52:27.000000Z",
"updated_at": "2023-08-15T15:52:27.000000Z",
"place": {
"id": 862,
"latitude": "45.1769555",
"longitude": "5.7333869",
"street_number": "29",
"route": "Chemin de l'Église",
"route2": null,
"locality": "Grenoble",
"sublocality": null,
"administrative_area_level_3": null,
"administrative_area_level_2": "Isère",
"administrative_area_level_1": "Auvergne-Rhône-Alpes",
"country": "France",
"countryiso2": null,
"postal_code": "38100",
"type": null,
"created_at": "2023-08-15T15:52:27.000000Z",
"updated_at": "2023-08-15T15:52:27.000000Z",
"formatted_address": "29 Chemin de l'Église - 38100 Grenoble - France",
"short_postal_code": "38",
"exported_address": "29 Chemin de l'Église"
},
"contacts": [
{
"id": 408,
"name": "Contact2 Sinao",
"job": "Support",
"phone": "Secret",
"email": "contact2@Sinao"
}
]
}
]
}
Et voila !
Updated about 1 year ago