@gohighlevel/api-client
Version:
Official SDK for HighLevel Public APIs
465 lines • 17.2 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Users = void 0;
/**
* Users Service
* Documentation for users API
*/
class Users {
constructor(httpClient) {
this.client = httpClient;
}
/**
* Search Users
* Search Users
*/
async searchUsers(params, options) {
let url = '/users/search';
const queryParams = {};
const headerParams = {};
// Extract security requirements for this endpoint
const securityRequirements = ["Agency-Access", "Location-Access"];
if (params) {
if (params.companyId !== undefined) {
queryParams['companyId'] = params.companyId;
}
if (params.query !== undefined) {
queryParams['query'] = params.query;
}
if (params.skip !== undefined) {
queryParams['skip'] = params.skip;
}
if (params.limit !== undefined) {
queryParams['limit'] = params.limit;
}
if (params.locationId !== undefined) {
queryParams['locationId'] = params.locationId;
}
if (params.type !== undefined) {
queryParams['type'] = params.type;
}
if (params.role !== undefined) {
queryParams['role'] = params.role;
}
if (params.ids !== undefined) {
queryParams['ids'] = params.ids;
}
if (params.sort !== undefined) {
queryParams['sort'] = params.sort;
}
if (params.sortDirection !== undefined) {
queryParams['sortDirection'] = params.sortDirection;
}
if (params.enabled2waySync !== undefined) {
queryParams['enabled2waySync'] = params.enabled2waySync;
}
}
// Collect all parameters for token resolution (including path params)
const allParams = {};
if (params) {
if (params.companyId !== undefined) {
allParams['companyId'] = params.companyId;
}
if (params.query !== undefined) {
allParams['query'] = params.query;
}
if (params.skip !== undefined) {
allParams['skip'] = params.skip;
}
if (params.limit !== undefined) {
allParams['limit'] = params.limit;
}
if (params.locationId !== undefined) {
allParams['locationId'] = params.locationId;
}
if (params.type !== undefined) {
allParams['type'] = params.type;
}
if (params.role !== undefined) {
allParams['role'] = params.role;
}
if (params.ids !== undefined) {
allParams['ids'] = params.ids;
}
if (params.sort !== undefined) {
allParams['sort'] = params.sort;
}
if (params.sortDirection !== undefined) {
allParams['sortDirection'] = params.sortDirection;
}
if (params.enabled2waySync !== undefined) {
allParams['enabled2waySync'] = params.enabled2waySync;
}
}
const config = {
method: 'GET',
url,
params: queryParams,
headers: {
...headerParams,
...options?.headers
},
...options
};
// Get appropriate authorization token based on security requirements
const ghlInstance = this.client.__ghlInstance;
if (ghlInstance && typeof ghlInstance.getTokenForSecurity === 'function') {
try {
// Combine headerParams with headers from options
const combinedHeaders = {
...headerParams,
...options?.headers
};
// Combine queryParams with allParams for token resolution
const combinedQuery = {
...queryParams,
...allParams
};
const authToken = await ghlInstance.getTokenForSecurity(securityRequirements, combinedHeaders, combinedQuery, {}, options?.preferredTokenType);
if (authToken) {
config.headers = {
...config.headers,
'Authorization': authToken
};
}
}
catch (error) {
throw error; // Re-throw authentication errors
}
}
const response = await this.client.request(config);
return response.data;
}
/**
* Filter Users by Email
* Filter users by company ID, deleted status, and email array
*/
async filterUsersByEmail(requestBody, options) {
let url = '/users/search/filter-by-email';
const queryParams = {};
const headerParams = {};
// Extract security requirements for this endpoint
const securityRequirements = ["Agency-Access", "Location-Access"];
// Collect all parameters for token resolution (including path params)
const allParams = {};
const config = {
method: 'POST',
url,
params: queryParams,
headers: {
...headerParams,
...options?.headers
},
data: requestBody,
...options
};
// Get appropriate authorization token based on security requirements
const ghlInstance = this.client.__ghlInstance;
if (ghlInstance && typeof ghlInstance.getTokenForSecurity === 'function') {
try {
// Combine headerParams with headers from options
const combinedHeaders = {
...headerParams,
...options?.headers
};
// Combine queryParams with allParams for token resolution
const combinedQuery = {
...queryParams,
...allParams
};
const authToken = await ghlInstance.getTokenForSecurity(securityRequirements, combinedHeaders, combinedQuery, requestBody, options?.preferredTokenType);
if (authToken) {
config.headers = {
...config.headers,
'Authorization': authToken
};
}
}
catch (error) {
throw error; // Re-throw authentication errors
}
}
const response = await this.client.request(config);
return response.data;
}
/**
* Get User
* Get User
*/
async getUser(params, options) {
let url = '/users/{userId}';
const queryParams = {};
const headerParams = {};
// Extract security requirements for this endpoint
const securityRequirements = ["Agency-Access", "Location-Access"];
if (params) {
if (params.userId !== undefined) {
url = url.replace('{' + 'userId' + '}', encodeURIComponent(String(params.userId)));
}
}
// Collect all parameters for token resolution (including path params)
const allParams = {};
if (params) {
if (params.userId !== undefined) {
allParams['userId'] = params.userId;
}
}
const config = {
method: 'GET',
url,
params: queryParams,
headers: {
...headerParams,
...options?.headers
},
...options
};
// Get appropriate authorization token based on security requirements
const ghlInstance = this.client.__ghlInstance;
if (ghlInstance && typeof ghlInstance.getTokenForSecurity === 'function') {
try {
// Combine headerParams with headers from options
const combinedHeaders = {
...headerParams,
...options?.headers
};
// Combine queryParams with allParams for token resolution
const combinedQuery = {
...queryParams,
...allParams
};
const authToken = await ghlInstance.getTokenForSecurity(securityRequirements, combinedHeaders, combinedQuery, {}, options?.preferredTokenType);
if (authToken) {
config.headers = {
...config.headers,
'Authorization': authToken
};
}
}
catch (error) {
throw error; // Re-throw authentication errors
}
}
const response = await this.client.request(config);
return response.data;
}
/**
* Update User
* Update User
*/
async updateUser(requestBody, options) {
let url = '/users/{userId}';
const queryParams = {};
const headerParams = {};
// Extract security requirements for this endpoint
const securityRequirements = ["Agency-Access", "Location-Access"];
// Collect all parameters for token resolution (including path params)
const allParams = {};
const config = {
method: 'PUT',
url,
params: queryParams,
headers: {
...headerParams,
...options?.headers
},
data: requestBody,
...options
};
// Get appropriate authorization token based on security requirements
const ghlInstance = this.client.__ghlInstance;
if (ghlInstance && typeof ghlInstance.getTokenForSecurity === 'function') {
try {
// Combine headerParams with headers from options
const combinedHeaders = {
...headerParams,
...options?.headers
};
// Combine queryParams with allParams for token resolution
const combinedQuery = {
...queryParams,
...allParams
};
const authToken = await ghlInstance.getTokenForSecurity(securityRequirements, combinedHeaders, combinedQuery, requestBody, options?.preferredTokenType);
if (authToken) {
config.headers = {
...config.headers,
'Authorization': authToken
};
}
}
catch (error) {
throw error; // Re-throw authentication errors
}
}
const response = await this.client.request(config);
return response.data;
}
/**
* Delete User
* Delete User
*/
async deleteUser(options) {
let url = '/users/{userId}';
const queryParams = {};
const headerParams = {};
// Extract security requirements for this endpoint
const securityRequirements = ["Agency-Access", "Location-Access"];
// Collect all parameters for token resolution (including path params)
const allParams = {};
const config = {
method: 'DELETE',
url,
params: queryParams,
headers: {
...headerParams,
...options?.headers
},
...options
};
// Get appropriate authorization token based on security requirements
const ghlInstance = this.client.__ghlInstance;
if (ghlInstance && typeof ghlInstance.getTokenForSecurity === 'function') {
try {
// Combine headerParams with headers from options
const combinedHeaders = {
...headerParams,
...options?.headers
};
// Combine queryParams with allParams for token resolution
const combinedQuery = {
...queryParams,
...allParams
};
const authToken = await ghlInstance.getTokenForSecurity(securityRequirements, combinedHeaders, combinedQuery, {}, options?.preferredTokenType);
if (authToken) {
config.headers = {
...config.headers,
'Authorization': authToken
};
}
}
catch (error) {
throw error; // Re-throw authentication errors
}
}
const response = await this.client.request(config);
return response.data;
}
/**
* Get User by Location
* Get User by Location
*/
async getUserByLocation(params, options) {
let url = '/users/';
const queryParams = {};
const headerParams = {};
// Extract security requirements for this endpoint
const securityRequirements = ["Location-Access"];
if (params) {
if (params.locationId !== undefined) {
queryParams['locationId'] = params.locationId;
}
}
// Collect all parameters for token resolution (including path params)
const allParams = {};
if (params) {
if (params.locationId !== undefined) {
allParams['locationId'] = params.locationId;
}
}
const config = {
method: 'GET',
url,
params: queryParams,
headers: {
...headerParams,
...options?.headers
},
...options
};
// Get appropriate authorization token based on security requirements
const ghlInstance = this.client.__ghlInstance;
if (ghlInstance && typeof ghlInstance.getTokenForSecurity === 'function') {
try {
// Combine headerParams with headers from options
const combinedHeaders = {
...headerParams,
...options?.headers
};
// Combine queryParams with allParams for token resolution
const combinedQuery = {
...queryParams,
...allParams
};
const authToken = await ghlInstance.getTokenForSecurity(securityRequirements, combinedHeaders, combinedQuery, {});
if (authToken) {
config.headers = {
...config.headers,
'Authorization': authToken
};
}
}
catch (error) {
throw error; // Re-throw authentication errors
}
}
const response = await this.client.request(config);
return response.data;
}
/**
* Create User
* Create User
*/
async createUser(requestBody, options) {
let url = '/users/';
const queryParams = {};
const headerParams = {};
// Extract security requirements for this endpoint
const securityRequirements = ["Agency-Access", "Location-Access"];
// Collect all parameters for token resolution (including path params)
const allParams = {};
const config = {
method: 'POST',
url,
params: queryParams,
headers: {
...headerParams,
...options?.headers
},
data: requestBody,
...options
};
// Get appropriate authorization token based on security requirements
const ghlInstance = this.client.__ghlInstance;
if (ghlInstance && typeof ghlInstance.getTokenForSecurity === 'function') {
try {
// Combine headerParams with headers from options
const combinedHeaders = {
...headerParams,
...options?.headers
};
// Combine queryParams with allParams for token resolution
const combinedQuery = {
...queryParams,
...allParams
};
const authToken = await ghlInstance.getTokenForSecurity(securityRequirements, combinedHeaders, combinedQuery, requestBody, options?.preferredTokenType);
if (authToken) {
config.headers = {
...config.headers,
'Authorization': authToken
};
}
}
catch (error) {
throw error; // Re-throw authentication errors
}
}
const response = await this.client.request(config);
return response.data;
}
}
exports.Users = Users;
exports.default = Users;
//# sourceMappingURL=users.js.map