Creates a new contact.
The info
object must include at least one of the following:
By default, if the call contains an email already in use by another contact,
the new contact won't be created. To override this behavior, set allowDuplicates
to true
.
This function requires elevated permissions and runs only on the backend and on dashboard pages.
function createContact(
info: ContactInfo,
options: CreateContactOptions,
): Promise<CreateContactResponse>;
Contact info.
Create contact options.
import { contacts } from "wix-crm.v2";
/* Sample contact info value:
* {
* name: {
* first: 'John',
* last: 'Doe'
* },
* emails: {
* items: [
* {
* email: 'johndoe1@example.com',
* }
* ]
* }
* }
*/
export async function myCreateContactFunction(info) {
try {
const newContact = await contacts.createContact(info);
console.log("Successfully created a new contact:", newContact);
return newContact;
} catch (error) {
console.log(error);
// Handle the error
}
}
/* Promise resolves to:
* {
* "revision": 1,
* "source": {
* "sourceType": "WIX_CODE",
* "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"
* },
* "lastActivity": {
* "activityDate": "2023-12-24T11:50:46.048Z",
* "activityType": "CONTACT_CREATED"
* },
* "primaryInfo": {
* "email": "johndoe1@example.com",
* "phone": "6465676359"
* },
* "info": {
* "name": {
* "first": "John",
* "last": "Doe"
* },
* "emails": {
* "items": [
* {
* "tag": "UNTAGGED",
* "email": "johndoe1@example.com",
* "primary": true,
* "_id": "37db3bde-83c0-4ca2-8097-88964a2f343b"
* }
* ]
* },
* "phones": {},
* "addresses": {},
* "extendedFields": {
* "items": {
* "contacts.displayByLastName": "Doe John",
* "invoices.vatId": "",
* "emailSubscriptions.deliverabilityStatus": "NOT_SET",
* "emailSubscriptions.subscriptionStatus": "UNSUBSCRIBED",
* "contacts.displayByFirstName": "John Doe"
* }
* }
* },
* "_id": "2712ae1d-3f64-46c2-ac3a-94a6c2e29847",
* "_createdDate": "2023-12-24T11:50:46.049Z",
* "_updatedDate": "2023-12-24T12:50:46.047Z"
* }
*/
There are 3 errors with this status code.
There are 2 errors with this status code.
This method may also return standard errors. Learn more about standard Wix errors.