Gå til indhold
Bekræftet

Tilføj en kontakt

Læg en person ind i kontaktbogen i hånden, og håndter tilfældet, hvor de allerede står i den.

create_contact er den indtastede vej ind i kontaktbogen, den samme som bag dashboardets egen formular "tilføj kontakt": et navn og en e-mail, med telefon og virksomhed som tilføjelse. Bogen er nøglet på e-mail, så det er ikke en fejl at sende en, der allerede findes, den kommer tilbage som en normal succes, der nævner den kontakt, 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.

Gennemgang

Send de fire felter, en kontakt har

name og email er de eneste to, create_contact kræver. source er som standard manual og context er Added by hand, hvis du udelader dem, begge vises i kontaktens egen aktivitetshistorik.

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 dublet-stien: e-mailen stod allerede i bogen, og contact_id angiver den kontakt, der allerede havde den, ikke en ny. Forgren på existed, ikke på code, for at skelne de to tilfælde, begge kommer tilbage som code: 1.

phone og company gemmes på kontakten, men gengives ikke i dette svar; læs dem tilbage med get_contacts eller get_contact_members, hvis du vil bekræfte, hvad der blev gemt.

Fejl

Næste