Créer et modifier une entreprise

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 Organization

parameters:
                - $ref: "#/components/parameters/appId"
                - name: id
                  in: path
                  description: "ID of organization"
                  required: true
                  schema:
                      type: integer
                - name: name
                  in: query
                  description: "Company name visible on the app"
                  schema:
                      type: string
                      pattern: "/^.*[a-z]+.*$/i" # minimum 1 letter
                      minimum: 2
                - name: billing_name
                  in: query
                  description: "Company name for billing"
                  schema:
                      type: string
                - name: logo
                  in: query
                  schema:
                      oneOf:
                          - type: string
                            format: byte
                          - type: string
                            format: uri
                - name: legal_form
                  in: query
                  schema:
                      type: string
                - name: country_iso2
                  in: query
                  schema:
                      type: string
                      format: "ISO 3166-1 alpha-2"
                - name: founding_date
                  in: query
                  schema:
                      type: string
                      format: date
                - name: founding_location
                  in: query
                  schema:
                      type: string
                - name: dissolution_date
                  in: query
                  schema:
                      type: string
                      format: date
                - name: vat_system
                  in: query
                  schema:
                      type: string
                - name: closeaccounting_period
                  in: query
                  schema:
                      type: string
                - name: national_id
                  in: query
                  description: "Unique National Id, format by country. **In France : [0-9]{9} with last number as security key.**"
                  schema:
                      type: string
                - name: vat_id
                  in: query
                  description: "European VAT Id. **In France : FR [0-9]{2} [0-9]{9}**"
                  schema:
                      nullable: true
                      type: string
                - name: code_naf
                  in: query
                  description: "French NAF Code"
                  schema:
                      nullable: true
                      type: string
                      pattern: "/^[0-9]{4}[a-z]$/i"
                - name: number_of_employees
                  in: query
                  schema:
                      type: string
                - name: slogan
                  in: query
                  schema:
                      type: string
                - name: rcs
                  in: query
                  description: "French. Registre du Commerce et des Sociétés"
                  schema:
                      type: string
                - name: greffe
                  in: query
                  description: "French. Tribunal de commerce"
                  schema:
                      type: string
                - name: capital
                  in: query
                  schema:
                      type: integer
                - 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 = "organizations" // type de contact organizations | persons
var new_name = "New Sinao";
var new_billingName = "NEW SINAO"
var request_params = `name=${new_name}&billing_name=${new_billingName}`;
// voir la liste dy YAML pour tous les paramètres disponibles.

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));
{
    "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"
}

requête d'update :

var myHeaders = new Headers();

myHeaders.append("Authorization", "Bearer <token>");

var app_id = 1; // votre app id
var contact_types = "organizations" // 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));
{
    "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"
}

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 = "organizations" // 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));
{
    "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 = "organizations" // 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));

{
    "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 = "organizations" // 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));

{
    "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 !