Sari la conținut
Verificat

Adaugă un contact

Introdu o persoană în agenda de contacte manual și tratează cazul în care există deja în ea.

create_contact este calea tastată manual spre agenda de contacte, aceeași din spatele formularului „adaugă contact” din tabloul de bord: un nume și un e-mail, cu telefon și companie ca adaos. Agenda este indexată după e-mail, așa că trimiterea unuia care există deja nu este o eroare, revine ca un succes obișnuit care numește contactul pe care îl ai deja.

Metodă

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.

Parcurgere

Trimite cele patru câmpuri pe care le are un contact

name și email sunt singurele două pe care le cere create_contact. source este implicit manual, iar context este implicit Added by hand dacă le omiți, ambele apar în istoricul de activitate al contactului.

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'])

Răspunsul

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

existed: true este calea duplicatului: e-mailul era deja în agendă, iar contact_id numește contactul care îl avea deja, nu unul nou. Ramifică după existed, nu după code, ca să deosebești cele două cazuri, ambele revin cu code: 1.

phone și company sunt stocate pe contact, dar nu sunt returnate în acest răspuns; citește-le înapoi cu get_contacts sau get_contact_members dacă vrei să confirmi ce s-a salvat.

Erori

Urmează