Zum Inhalt springen
Geprüft

Einen Kontakt hinzufügen

Lege eine Person von Hand im Kontaktbuch an und behandle den Fall, dass sie schon darin steht.

create_contact ist der Weg, einen Kontakt von Hand ins Kontaktbuch einzutragen, derselbe wie hinter dem Formular "Kontakt hinzufügen" des Dashboards: ein Name und eine E-Mail-Adresse, dazu optional Telefon und Firma. Das Buch ist nach E-Mail-Adresse geschlüsselt, daher ist das Senden einer bereits vorhandenen kein Fehler, sondern kommt als normaler Erfolg zurück und nennt den Kontakt, den du schon hast.

Methode

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.

Schritt für Schritt

Sende die vier Felder, die ein Kontakt hat

name und email sind die einzigen beiden Felder, die create_contact verlangt. source ist standardmäßig manual und context standardmäßig Added by hand, wenn du sie weglässt. Beide erscheinen im eigenen Aktivitätsverlauf des Kontakts.

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

Die Antwort

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

existed: true ist der Duplikatpfad: Die E-Mail-Adresse war bereits im Buch, und contact_id nennt den Kontakt, der sie schon hatte, nicht einen neuen. Unterscheide die beiden Fälle über existed, nicht über code, beide kommen als code: 1 zurück.

phone und company werden am Kontakt gespeichert, aber in dieser Antwort nicht zurückgegeben. Lies sie mit get_contacts oder get_contact_members zurück, wenn du bestätigen willst, was gespeichert wurde.

Fehler

Weiter