Hoppa till innehållet
Verifierad

Lägg till en kontakt

Lägg in en person i kontaktboken för hand, och hantera fallet att de redan finns där.

create_contact är den inskrivna vägen in i kontaktboken, samma som ligger bakom instrumentpanelens eget formulär "Lägg till en kontakt": ett namn och en e-postadress, med telefon och företag som tillägg. Boken nycklas på e-postadress, så att skicka en som redan finns är inget fel, det kommer tillbaka som en vanlig framgång som namnger den kontakt du redan har.

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.

Genomgång

Skicka de fyra fält en kontakt har

name och email är de enda två som create_contact kräver. source är som standard manual och context är Added by hand om du utelämnar dem, och båda visas i 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 är dubblettvägen: e-postadressen fanns redan i boken, och contact_id namnger den kontakt som redan hade den, inte en ny. Förgrena på existed, inte på code, för att skilja de två fallen åt, båda kommer tillbaka som code: 1.

phone och company sparas på kontakten men ekas inte tillbaka i det här svaret; läs tillbaka dem med get_contacts eller get_contact_members om du behöver bekräfta vad som sparades.

Fel

Nästa