Hopp til innholdet
Bekreftet

Legg til en kontakt

Før en person inn i kontaktboken for hånd, og håndter tilfellet der de allerede står i den.

create_contact er veien for innskrevne data inn i kontaktboken, den samme som ligger bak oversiktspanelets eget skjema for å legge til en kontakt: et navn og en e-post, med telefon og firma som tillegg. Boken har e-post som nøkkel, så å sende en som allerede finnes er ikke en feil, det kommer tilbake som en vanlig suksess som navngir kontakten du allerede har.

Metode

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.

Gjennomgang

Send de fire feltene en kontakt har

name og email er de eneste to create_contact krever. source er manual som standard og context er Added by hand hvis du utelater dem, begge vises på kontaktens egen aktivitetslogg.

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

Svaret

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

existed: true er duplikatveien: e-posten fantes allerede i boken, og contact_id navngir kontakten som allerede hadde den, ikke en ny. Forgren på existed, ikke på code, for å skille de to tilfellene, begge kommer tilbake som code: 1.

phone og company lagres på kontakten, men gjentas ikke i dette svaret. Les dem tilbake med get_contacts eller get_contact_members hvis du trenger å bekrefte hva som ble lagret.

Feil

Neste