11// File: organizations.js
22const { Client} = require ( '../client' ) ;
33
4+ /**
5+ * Organizations are typically collections of your end users, but they can also include team members.
6+ * @typedef {object } Organization
7+ * @property {string } created_at - The time the organization was created (read-only)
8+ * @property {string } [details] - Any details about the organization, such as the address
9+ * @property {string[] } [domain_names] - An array of domain names associated with this organization
10+ * @property {string } [external_id] - A unique external id to associate organizations to an external record. The id is case-insensitive
11+ * @property {number } [group_id] - New tickets from users in this organization are automatically put in this group
12+ * @property {number } [id] - Automatically assigned when the organization is created
13+ * @property {string } name - A unique name for the organization (mandatory)
14+ * @property {string } [notes] - Any notes you have about the organization
15+ * @property {{[field_name: string]: string|null} } [organization_fields] - Custom fields for this organization
16+ * @property {boolean } [shared_comments] - End users in this organization are able to comment on each other's tickets
17+ * @property {boolean } [shared_tickets] - End users in this organization are able to see each other's tickets
18+ * @property {string[] } [tags] - The tags of the organization
19+ * @property {string } updated_at - The time of the last update of the organization (read-only)
20+ * @property {string } url - The API url of this organization (read-only)
21+ */
22+
23+ /**
24+ * @typedef {Omit<Organization, 'id' | 'created_at' | 'updated_at' | 'url'> } OrganizationCreate
25+ */
26+
27+ /**
28+ * @typedef {Partial<Omit<Organization, 'id' | 'created_at' | 'updated_at' | 'url'>> } OrganizationUpdate
29+ */
30+
31+ /**
32+ * @typedef {Partial<Omit<Organization, 'created_at' | 'updated_at' | 'url'>> & Pick<Organization, 'id'> } OrganizationUpdateMany
33+ */
34+
35+ /**
36+ * @typedef {object } OrganizationRelatedResponse
37+ * @property {object } organization_related - Information about objects related to the organization.
38+ * @property {number } organization_related.tickets_count - The number of tickets related to the organization.
39+ * @property {number } organization_related.users_count - The number of users related to the organization.
40+ */
41+
442/**
543 * @class
644 * Client for interacting with the Zendesk Organizations API.
@@ -14,7 +52,7 @@ class Organizations extends Client {
1452
1553 /**
1654 * Lists all organizations.
17- * @returns {Promise<object > } The list of organizations.
55+ * @returns {Promise<Organization[] > } The list of organizations.
1856 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#list-organizations }
1957 * @example const organizations = await client.organizations.list();
2058 */
@@ -25,7 +63,7 @@ class Organizations extends Client {
2563 /**
2664 * Lists organizations associated with a specific user.
2765 * @param {number } userID - The ID of the user.
28- * @returns {Promise<object []> } List of organizations associated with the user.
66+ * @returns {Promise<Organization []> } List of organizations associated with the user.
2967 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#list-organizations }
3068 * @example const userOrgs = await client.organizations.listByUser(12345);
3169 */
@@ -64,7 +102,7 @@ class Organizations extends Client {
64102 /**
65103 * Retrieves related information for a specific organization.
66104 * @param {number } organizationID - The ID of the organization.
67- * @returns {Promise<{response: object, result: object }> } Object containing related information of the organization.
105+ * @returns {Promise<{response: object, result: OrganizationRelatedResponse }> } Object containing related information of the organization.
68106 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organizations-related-information }
69107 * @example const relatedInfo = await client.organizations.related(12345);
70108 */
@@ -75,7 +113,7 @@ class Organizations extends Client {
75113 /**
76114 * Views a specific organization by its ID.
77115 * @param {number } organizationID - The ID of the organization.
78- * @returns {Promise<{response: object, result: object }> } The organization's details.
116+ * @returns {Promise<{response: object, result: Organization }> } The organization's details.
79117 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organization }
80118 * @example const organization = await client.organizations.show(12345);
81119 */
@@ -86,7 +124,7 @@ class Organizations extends Client {
86124 /**
87125 * Retrieves details of multiple organizations based on their IDs.
88126 * @param {number[] } organizationIDs - Array of organization IDs.
89- * @returns {Promise<object []> } List of organizations' details.
127+ * @returns {Promise<Organization []> } List of organizations' details.
90128 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-many-organizations }
91129 * @example const orgDetails = await client.organizations.showMany([12345, 67890]);
92130 */
@@ -103,7 +141,7 @@ class Organizations extends Client {
103141 /**
104142 * Retrieves details of multiple organizations based on their External IDs.
105143 * @param {string[] } externalOrganizationIds - Array of organization IDs.
106- * @returns {Promise<object []> } List of organizations' details.
144+ * @returns {Promise<Organization []> } List of organizations' details.
107145 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-many-organizations }
108146 * @example const orgDetails = await client.organizations.showMany(['12345', '67890']);
109147 */
@@ -119,64 +157,64 @@ class Organizations extends Client {
119157
120158 /**
121159 * Creates a new organization.
122- * @param {object } organization - The organization object to create.
123- * @returns {Promise<{response: object, result: object }> } The created organization's details.
160+ * @param {OrganizationCreate } organization - The organization object to create.
161+ * @returns {Promise<{response: object, result: Organization }> } The created organization's details.
124162 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-organization }
125163 * @example const newOrganization = await client.organizations.create({ name: 'New Org' });
126164 */
127165 async create ( organization ) {
128- return this . post ( [ 'organizations' ] , organization ) ;
166+ return this . post ( [ 'organizations' ] , { organization} ) ;
129167 }
130168
131169 /**
132170 * Creates multiple organizations.
133- * @param {object [] } organizations - An array of organization objects to create.
134- * @returns {Promise<{response: object, result: object []}> } Details of the created organizations.
171+ * @param {OrganizationCreate [] } organizations - An array of organization objects to create.
172+ * @returns {Promise<{response: object, result: Organization []}> } Details of the created organizations.
135173 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-many-organizations }
136174 * @example const newOrganizations = await client.organizations.createMany([{ name: 'Org1' }, { name: 'Org2' }]);
137175 */
138176 async createMany ( organizations ) {
139- return this . post ( [ 'organizations' , 'create_many' ] , organizations ) ;
177+ return this . post ( [ 'organizations' , 'create_many' ] , { organizations} ) ;
140178 }
141179
142180 /**
143181 * Creates or updates an organization.
144- * @param {object } organization - The organization object to create or update.
145- * @returns {Promise<{response: object, result: object }> } The created or updated organization's details.
182+ * @param {OrganizationCreate|OrganizationUpdate } organization - The organization object to create or update.
183+ * @returns {Promise<{response: object, result: Organization }> } The created or updated organization's details.
146184 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-or-update-organization }
147185 * @example const org = await client.organizations.createOrUpdate({ id: 12345, name: 'Updated Name' });
148186 */
149187 async createOrUpdate ( organization ) {
150- return this . post ( [ 'organizations' , 'create_or_update' ] , organization ) ;
188+ return this . post ( [ 'organizations' , 'create_or_update' ] , { organization} ) ;
151189 }
152190
153191 /**
154192 * Updates a specific organization by its ID.
155193 * @param {number } organizationID - The ID of the organization.
156- * @param {object } organization - The updated organization object.
157- * @returns {Promise<{response: object, result: object }> } The updated organization's details.
194+ * @param {Omit<OrganizationUpdate, 'id'> } organization - The updated organization object.
195+ * @returns {Promise<{response: object, result: Organization }> } The updated organization's details.
158196 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#update-organization }
159197 * @example const updatedOrganization = await client.organizations.update(12345, { name: 'New Name' });
160198 */
161199 async update ( organizationID , organization ) {
162- return this . put ( [ 'organizations' , organizationID ] , organization ) ;
200+ return this . put ( [ 'organizations' , organizationID ] , { organization} ) ;
163201 }
164202
165203 /**
166204 * Updates multiple organizations.
167- * @param {object [] } organizations - An array of organization objects to update.
168- * @returns {Promise<{response: object, result: object []}> } Details of the updated organizations.
205+ * @param {OrganizationUpdateMany [] } organizations - An array of organization objects to update.
206+ * @returns {Promise<{response: object, result: Organization []}> } Details of the updated organizations.
169207 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#update-many-organizations }
170208 * @example const updatedOrganizations = await client.organizations.updateMany([{ id: 1, name: 'Updated Org1' }, { id: 2, name: 'Updated Org2' }]);
171209 */
172210 async updateMany ( organizations ) {
173- return this . put ( [ 'organizations' , 'update_many' ] , organizations ) ;
211+ return this . put ( [ 'organizations' , 'update_many' ] , { organizations} ) ;
174212 }
175213
176214 /**
177215 * Creates or updates an organization, similar to `createOrUpdate` method.
178- * @param {object } organization - The organization object to upsert.
179- * @returns {Promise<{response: object, result: object }> } The created or updated organization's details.
216+ * @param {OrganizationUpdate|OrganizationCreate } organization - The organization object to upsert.
217+ * @returns {Promise<{response: object, result: Organization }> } The created or updated organization's details.
180218 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-or-update-organization }
181219 * @example const org = await client.organizations.upsert({ id: 12345, name: 'Upserted Name' });
182220 */
@@ -235,7 +273,7 @@ class Organizations extends Client {
235273 /**
236274 * Searches organizations based on external ID.
237275 * @param {number } externalID - Search by externalID.
238- * @returns {Promise<object []> } List of organizations matching the search.
276+ * @returns {Promise<Organization []> } List of organizations matching the search.
239277 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#search-organizations-by-external-id }
240278 * @example const foundOrganizations = await client.organizations.search(1234);
241279 */
@@ -246,7 +284,7 @@ class Organizations extends Client {
246284 /**
247285 * Autocompletes organization names based on provided parameters.
248286 * @param {object } parameters - Parameters for autocomplete.
249- * @returns {Promise<object []> } List of organizations matching the autocomplete.
287+ * @returns {Promise<Organization []> } List of organizations matching the autocomplete.
250288 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#autocomplete-organizations }
251289 * @example const autocompleteResults = await client.organizations.autocomplete({ name: 'Test' });
252290 */
@@ -258,7 +296,7 @@ class Organizations extends Client {
258296 * Incrementally exports organizations with an include parameter.
259297 * @param {string|Date } startTime - Start time for incremental export.
260298 * @param {string } include - Data to include in the export.
261- * @returns {Promise<object []> } List of organizations in the incremental export.
299+ * @returns {Promise<Organization []> } List of organizations in the incremental export.
262300 * @see {@link https://developer.zendesk.com/api-reference/ticketing/ticket-management/incremental_exports/#incremental-organization-export }
263301 * @example const exportedOrganizations = await client.organizations.incrementalInclude('2023-01-01T12:00:00Z', 'users');
264302 */
@@ -273,7 +311,7 @@ class Organizations extends Client {
273311 /**
274312 * Incrementally exports organizations.
275313 * @param {string|Date } startTime - Start time for incremental export.
276- * @returns {Promise<object []> } List of organizations in the incremental export.
314+ * @returns {Promise<Organization []> } List of organizations in the incremental export.
277315 * @see {@link https://developer.zendesk.com/api-reference/ticketing/ticket-management/incremental_exports/#incremental-organization-export }
278316 * @example const exportedOrganizations = await client.organizations.incremental('2023-01-01T12:00:00Z');
279317 */
@@ -288,7 +326,7 @@ class Organizations extends Client {
288326 /**
289327 * Fetches a sample of incremental organization exports.
290328 * @param {string|Date } startTime - Start time for the sample.
291- * @returns {Promise<{response: object, result: object []}> } Sample list of organizations in the incremental export.
329+ * @returns {Promise<{response: object, result: Organization []}> } Sample list of organizations in the incremental export.
292330 * @see {@link https://developer.zendesk.com/api-reference/ticketing/ticket-management/incremental_exports/#incremental-sample-export }
293331 * @example const sampleExportedOrganizations = await client.organizations.incrementalSample('2023-01-01T12:00:00Z');
294332 */
0 commit comments