Vai al contenuto
Verificata

Aggiungere un contatto

Archivia una persona nella rubrica a mano e gestisci il caso in cui sia già presente.

create_contact è il percorso di inserimento manuale nella rubrica, lo stesso che sta dietro al modulo "Aggiungi contatto" della dashboard: un nome e un'email, più telefono e azienda come extra. La rubrica usa l'email come chiave, quindi inviarne una che esiste già non è un errore: torna come un normale successo che indica il contatto che hai già.

Metodo

POST/cpi/create_contact
user

Create Contact

Adds a person to the contact book by hand, from typed details rather than from a received message. Takes only the fields a contact has, name, email, phone, company, job title and its kind (personal or business, which then needs no model to classify it), and ignores anything else the caller happens to hold, such as a shipping address. The email is the book's key, so it is required and a repeat of one already filed returns the existing contact instead of a second copy.

Procedura

Invia i quattro campi di un contatto

name ed email sono gli unici due campi che create_contact richiede. Se li ometti, source vale manual e context vale Added by hand; entrambi compaiono nella cronologia di attività del contatto.

curl -s https://xuda.ai/cpi/create_contact \
  -H 'content-type: application/json' \
  -d '{
    "api_key": "YOUR_API_KEY",
    "name": "Priya Shah",
    "email": "[email protected]",
    "phone": "+1 555 0110",
    "company": "Northwind"
  }'
const res = await fetch('https://xuda.ai/cpi/create_contact', {
  method: 'POST',
  headers: { 'content-type': 'application/json' },
  body: JSON.stringify({
    api_key: 'YOUR_API_KEY',
    name: 'Priya Shah',
    email: '[email protected]',
    phone: '+1 555 0110',
    company: 'Northwind',
  }),
});
const { code, data } = await res.json();
if (code > 0 && data.existed) console.log('already in the book:', data.contact_id);
else if (code > 0) console.log('created:', data.contact_id);
import requests

res = requests.post(
    'https://xuda.ai/cpi/create_contact',
    json={
        'api_key': 'YOUR_API_KEY',
        'name': 'Priya Shah',
        'email': '[email protected]',
        'phone': '+1 555 0110',
        'company': 'Northwind',
    },
)
body = res.json()
if body['code'] > 0 and body['data']['existed']:
    print('already in the book:', body['data']['contact_id'])
elif body['code'] > 0:
    print('created:', body['data']['contact_id'])

La risposta

json
{
  "code": 1,
  "data": {
    "contact_id": "cnt_a91f0e",
    "name": "Priya Shah",
    "email": "[email protected]",
    "existed": false
  }
}

existed: true è il caso del duplicato: l'email era già nella rubrica e contact_id indica il contatto che la aveva già, non uno nuovo. Per distinguere i due casi, ramifica su existed e non su code: entrambi tornano con code: 1.

phone e company vengono salvati sul contatto ma non restituiti in questa risposta; rileggili con get_contacts o get_contact_members se ti serve confermare cosa è stato salvato.

Errori

Passi successivi