Send customer data from backend system to Gillie.
This example creates a new customer or if customer exists with person_id, then updates the customer.
After that program gets the customer information from Gillie with Gillie’s internal id.
Checklist
- Does backend system has a unique key for person. Use that as person_id field in Gillie.
- Can you detect updates - it’s always faster to send just updated and new customers than update always all of them
- Can you detect deletes - most common way to handle this in Gillie is to turn customer’s “archived”-flag on
- Do you need restrictions for the customers - some users are permitted to see only certain customers. Teams in Gillie are meant for that. Check our teams-API and customer_team_ids in customer collection.
Customer’s tags and teams
In some cases backend system also creates/updates Gillie’s teams and tags. These have their own API calls, which backend system can use, if needed.
Example
const GillieApi = require('gillie-api').GillieApi;
const api = new GillieApi(
{publicKey: "...public key here...",
privateKey: "...private key here..."
});
example();
async function example() {
// Create or update customer. (upsert parameter tells that this call also updates)
// Makes a post call to URL
// https://test.gillie.io/api/customers?upsert=true&..apikey & hash code in URL
// And post data is the contents of last parameter
// external\_id: Customer number in backend system
let insertedCustomer = await api.post("/api/customers",
{
first_name: "Matt",
last_name: "Smith",
person_id: "12378907778",
street_address1: "Mannerheimintie 1B",
street_address2: "",
zip_code: "00100",
phone: "+358509998888",
archived: false
},{ upsert: true });
console.log("INSERTED CUSTOMER", insertedCustomer);
// Get customer with gillie's internal id
let getCustomer = await api.get("/api/customers/" + insertedCustomer._id);
console.log("GOT Customer", getCustomer);
}