İçeriğe geç
Doğrulandı

Kişi ekleyin

Bir kişiyi elle kişi defterine kaydedin ve zaten defterde olması durumunu ele alın.

create_contact, kişi defterine elle girilen yoldur ve panonun kendi "kişi ekle" formunun arkasındaki aynı yoldur: bir ad ve bir e-posta, yanında telefon ve şirket. Defter e-postaya göre anahtarlanır. Bu yüzden zaten var olan birini göndermek hata değildir: elinizdeki kişiyi belirten normal bir başarı olarak döner.

Yöntem

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.

Anlatım

Bir kişinin sahip olduğu dört alanı gönderin

create_contact yalnızca name ve email alanlarını zorunlu tutar. Atlarsanız source varsayılan olarak manual, context ise Added by hand olur. İkisi de kişinin kendi etkinlik geçmişinde gösterilir.

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

Yanıt

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

existed: true yinelenen yoldur: e-posta zaten defterdeydi ve contact_id, yeni bir kişiyi değil o e-postaya zaten sahip olan kişiyi belirtir. İki durumu ayırmak için code değerine değil existed değerine göre dallanın, ikisi de code: 1 olarak döner.

phone ve company kişide saklanır ama bu yanıtta yansıtılmaz. Neyin kaydedildiğini doğrulamanız gerekirse get_contacts veya get_contact_members ile geri okuyun.

Hatalar

Sonraki