gohl
Version:
Go Highlevel Node Js ease of use library implementation to their API
208 lines • 11 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Contacts = void 0;
const axios_1 = require("axios");
const contacts_tasks_1 = require("./contacts.tasks");
const contacts_notes_1 = require("./contacts.notes");
const contacts_campaigns_1 = require("./contacts.campaigns");
const contacts_workflows_1 = require("./contacts.workflows");
const contacts_tags_1 = require("./contacts.tags");
const contacts_appointments_1 = require("./contacts.appointments");
class Contacts {
/**
* Endpoints For Contacts
* https://highlevel.stoplight.io/docs/integrations/e957726e8625d-contacts-api
* https://public-api.gohighlevel.com/#0097b747-33c2-452f-8c78-aab5ab36c071
*/
constructor(authData) {
this.appointments = new contacts_appointments_1.Appointment(authData);
this.campaigns = new contacts_campaigns_1.Campaign(authData);
this.workflows = new contacts_workflows_1.Workflow(authData);
this.tasks = new contacts_tasks_1.Task(authData);
this.notes = new contacts_notes_1.Note(authData);
this.tags = new contacts_tags_1.Tag(authData);
this.authData = authData;
}
/**
* Get contacts. [Deprecated]
* Documentation - https://highlevel.stoplight.io/docs/integrations/dbe4f3a00a106-search-contacts
* @param locationId
* @param filters
* @returns
*/
get(locationId, filters) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b;
const headers = (_a = this.authData) === null || _a === void 0 ? void 0 : _a.headers;
let q = ``;
if (filters.query)
q = `&query=${filters.query}`;
if (filters.startAfter)
q = `&startAfter=${filters.startAfter}`;
if (filters.startAfterId)
q = `&startAfterId=${filters.startAfterId}`;
if (filters.limit)
q = `&limit=${filters.limit}`;
const response = yield axios_1.default.get(`${(_b = this.authData) === null || _b === void 0 ? void 0 : _b.baseurl}/contacts?locationId=${locationId}${q}`, { headers });
const contacts = response.data.contacts;
const count = response.data.count;
return { count, contacts };
});
}
/**
* Get Contacts and Search contacts. For both App and API version
* Documentation - https://highlevel.stoplight.io/docs/integrations/dbe4f3a00a106-search-contacts
* Documentation - https://public-api.gohighlevel.com/#dac71866-cddd-48e9-ba77-99fd293594fa
* @param query
* @param order
* @param sortBy
* @param limit
*/
search() {
return __awaiter(this, arguments, void 0, function* (query = '', order = 'desc', sortBy = 'date_added', limit = 20) {
var _a, _b, _c, _d;
const headers = (_a = this.authData) === null || _a === void 0 ? void 0 : _a.headers;
if ((_b = this.authData) === null || _b === void 0 ? void 0 : _b.useAPIKey) {
const response = yield axios_1.default.get(`${(_c = this.authData) === null || _c === void 0 ? void 0 : _c.baseurl}/contacts/?limit=${limit}&query=${query}&sortBy=${sortBy}&order=${order}`, { headers });
const contacts = response.data.contacts;
const total = response.data.meta.total;
return { total, contacts };
}
else {
const body = {};
const response = yield axios_1.default.post(`${(_d = this.authData) === null || _d === void 0 ? void 0 : _d.baseurl}/contacts/search/`, body, { headers });
const contacts = response.data.contacts;
const total = response.data.total;
return { total, contacts };
}
});
}
/**
* Get Searched contacts use filters.
* Documentation - https://highlevel.stoplight.io/docs/integrations/dbe4f3a00a106-search-contacts
* Documnetation on Filters - https://doc.clickup.com/8631005/d/h/87cpx-158396/6e629989abe7fad
* @param query
*/
searchWithFilters(query) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b;
const headers = (_a = this.authData) === null || _a === void 0 ? void 0 : _a.headers;
const response = yield axios_1.default.post(`${(_b = this.authData) === null || _b === void 0 ? void 0 : _b.baseurl}/contacts/search/`, query, { headers });
const contacts = response.data.contacts;
const total = response.data.total;
return { total, contacts };
});
}
/**
* Search contact by email or phone number.. Only For API version
* Documentation - https://public-api.gohighlevel.com/#5f4bde90-5179-43b2-b38d-f09b7bb771ad
* @param email
* @param phone
*/
lookup() {
return __awaiter(this, arguments, void 0, function* (email = "", phone = "") {
var _a, _b, _c;
const headers = (_a = this.authData) === null || _a === void 0 ? void 0 : _a.headers;
if ((_b = this.authData) === null || _b === void 0 ? void 0 : _b.useAPIKey) {
const response = yield axios_1.default.get(`${(_c = this.authData) === null || _c === void 0 ? void 0 : _c.baseurl}/contacts/lookup?email=${email}&phone=${phone}`, { headers });
const contacts = response.data.contacts;
return contacts;
}
else {
throw new Error("You need to use an API key to call this function. Look at the documentation here https://public-api.gohighlevel.com/#5f4bde90-5179-43b2-b38d-f09b7bb771ad");
}
});
}
/**
* Get Contacts By BusinessId
* Documentation: https://highlevel.stoplight.io/docs/integrations/8efc6d5a99417-get-contacts-by-business-id
* @param businessId
* @returns
*/
getByBusinessId(businessId) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b;
const headers = (_a = this.authData) === null || _a === void 0 ? void 0 : _a.headers;
const response = yield axios_1.default.get(`${(_b = this.authData) === null || _b === void 0 ? void 0 : _b.baseurl}/contacts/business/${businessId}`, { headers });
const contacts = response.data.contacts;
const total = response.data.count;
return { total, count: total, contacts };
});
}
/**
* Get Contacts By Id. For other GHL App and API version
* Documentation: https://highlevel.stoplight.io/docs/integrations/00c5ff21f0030-get-contact
* @param contactId
* @returns
*/
getOne(contactId) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b;
const headers = (_a = this.authData) === null || _a === void 0 ? void 0 : _a.headers;
const response = yield axios_1.default.get(`${(_b = this.authData) === null || _b === void 0 ? void 0 : _b.baseurl}/contacts/${contactId}`, { headers });
const c = response.data.contact;
return c;
});
}
/**
* Creates a new contact with the provided information. For other GHL App and API version
* Documentation: https://public-api.gohighlevel.com/#5fbc2b83-603d-4974-81c3-7d8658a79594
* @param {CreateContactInfo} contact - The contact information including email, name, phone, company, and source.
* @returns The newly created contact.
*/
create(contact_1) {
return __awaiter(this, arguments, void 0, function* (contact, locationId = "") {
var _a, _b, _c, _d;
const l = locationId ? locationId : (_a = this.authData) === null || _a === void 0 ? void 0 : _a.locationId;
const headers = (_b = this.authData) === null || _b === void 0 ? void 0 : _b.headers;
const body = ((_c = this.authData) === null || _c === void 0 ? void 0 : _c.useAPIKey) ? contact : Object.assign(Object.assign({}, contact), { locationId: l });
const response = yield axios_1.default.post(`${(_d = this.authData) === null || _d === void 0 ? void 0 : _d.baseurl}/contacts/`, body, { headers });
const c = response.data.contact;
return c;
});
}
/**
* Update contact. For other GHL App and API version
* Documentation: https://highlevel.stoplight.io/docs/integrations/9ce5a739d4fb9-update-contact
* Documentation: https://public-api.gohighlevel.com/#1c7060e2-ebaf-4b5b-9248-be0292689bba
* @param {string} id
* @param contact
* @returns
*/
update(id_1, contact_1) {
return __awaiter(this, arguments, void 0, function* (id, contact, locationId = "") {
var _a, _b, _c, _d;
const l = locationId ? locationId : (_a = this.authData) === null || _a === void 0 ? void 0 : _a.locationId;
const headers = (_b = this.authData) === null || _b === void 0 ? void 0 : _b.headers;
const body = ((_c = this.authData) === null || _c === void 0 ? void 0 : _c.useAPIKey) ? contact : Object.assign(Object.assign({}, contact), { locationId: l });
const response = yield axios_1.default.put(`${(_d = this.authData) === null || _d === void 0 ? void 0 : _d.baseurl}/contacts/${id}`, body, { headers });
const c = response.data.contact;
return c;
});
}
/**
* Remove contact. For other GHL App and API version
* Documentation: https://highlevel.stoplight.io/docs/integrations/28ab84e9522b6-delete-contact
* Documentation: https://public-api.gohighlevel.com/#546cdf6c-3367-4569-b3c4-46d9f13a71ba
* @param id
*/
remove(id) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c;
const headers = (_a = this.authData) === null || _a === void 0 ? void 0 : _a.headers;
const response = yield axios_1.default.delete(`${(_b = this.authData) === null || _b === void 0 ? void 0 : _b.baseurl}/contacts/${id}`, { headers });
return (((_c = response.data) === null || _c === void 0 ? void 0 : _c.succeded) || true);
});
}
}
exports.Contacts = Contacts;
//# sourceMappingURL=contacts.js.map