The newContact function returns a Contact object. The Contact created is only known locally, it has not been saved to the Wix Hive and does not have an ID.
To share your Contact with the Wix Hive, use the create function as shown below.
var contact =api.Contacts.newContact(api);// Created a new Contact object. This Contact is only known locally, at this point it has not been saved to the Wix Hive.
// Do more stuff with the returned updated contact
},
function(error){
throw error;
}
);
},
function(error){
throw error;
}
);
Explicit property update methods
To explicitly and immediately update Contact properties use the Contact.update methods. These methods make an HTTP PUT call to one of the /contacts/{contactId}/ endpoints.
We recommend using the Contact.update method if you need to change more than one property at a time.
The example below shows how to update the name property of a Contact.
var contact =api.Contacts.newContact();
contact.name({first:'Karen', last:'Meep'});
api.Contacts.create(contact).then(
function(contact){
contact.name().prefix('Sir');
contact.name().first('Mix');
contact.name().middle('A');
contact.name().last('Lot');
contact.name().suffix('The III');
contact.updateName().then(
function(contact){
// ...
},
function(error){
throw error;
}
);
},
function(error){
throw error;
}
);
Post an activity against a Contact
The code below posts an Activity against the given Contact.
Note: Use the Activities.postActivity function to post an Activity in no relation to a Contact.
var activity =api.Activities.newActivity(api.Activities.TYPES.ALBUM_FAN);
activityTypes:[api.Activities.TYPES.ALBUM_FAN.name,api.Activities.TYPES.ALBUM_SHARE.name],// Filter by Activity type
scope:'app',// or 'site'
pageSize:50// or 25, 100
}
).then(function(pagingActivitiesResult){
// Use the cursor to page through more Activities..
},function(error){
throw error;
});
Post An Activity
Obtain a User Session Token
This is where the Javascript SDK comes in to play. Use it to obtain a user session token, then use the token to create an activity on behalf of the user.
Here's an example of how to obtain the session token and then sending it to the NodeJS server
To create an Activity either use our builder (as shown in the Contact Form Activity example below) or use a JSON, following our Activity schemas (as shown in the Ecommerce Purchase Activity example below)
Create an Activity Using JSON
var activity =api.Activities.newActivity(api.Activities.TYPES.ECOMMERCE_PURCHASE);
var coupon ={total:'1', title:'Dis'};
var payment ={total:'1', subtotal:'1', currency:'EUR', coupon: coupon};
var purchase ={ items:[], cartId:'11111', storeId:'11111', payment: payment };
Use the session token on your Node server to create an activity an post it to the Wix Hive.
Note: This code posts an Activity without any connection to a Contact. To post an Activity against a Contact use the Contact.addActivity method.