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 {{
25+ * organization: Omit<Organization, 'id' | 'created_at' | 'updated_at' | 'url'>
26+ * }} CreateOrganization
27+ */
28+
29+ /**
30+ * @typedef {{
31+ * organizations: Omit<Organization, 'id' | 'created_at' | 'updated_at' | 'url'>[]
32+ * }} CreateManyOrganizations
33+ */
34+
35+ /**
36+ * @typedef {{
37+ * organization: Partial<Omit<Organization, 'id' | 'created_at' | 'updated_at' | 'url'>>
38+ * }} UpdateOrganization
39+ */
40+
41+ /**
42+ * @typedef {{
43+ * organizations: (
44+ * Partial<Omit<Organization, 'id' | 'created_at' | 'updated_at' | 'url'>>
45+ * & Pick<Organization, 'id'>
46+ * )
47+ * }} UpdateOrganizationWithId
48+ */
49+
50+ /**
51+ * @typedef {{
52+ * organizations: (
53+ * Partial<Omit<Organization, 'id' | 'created_at' | 'updated_at' | 'url'>>
54+ * & Pick<Organization, 'id'>
55+ * )[]
56+ * }} UpdateManyOrganizations
57+ */
58+
59+ /**
60+ * @typedef {object } OrganizationRelatedResponse
61+ * @property {object } organization_related - Information about objects related to the organization.
62+ * @property {number } organization_related.tickets_count - The number of tickets related to the organization.
63+ * @property {number } organization_related.users_count - The number of users related to the organization.
64+ */
65+
466/**
567 * @class
668 * Client for interacting with the Zendesk Organizations API.
@@ -14,7 +76,7 @@ class Organizations extends Client {
1476
1577 /**
1678 * Lists all organizations.
17- * @returns {Promise<object > } The list of organizations.
79+ * @returns {Promise<Organization[] > } The list of organizations.
1880 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#list-organizations }
1981 * @example const organizations = await client.organizations.list();
2082 */
@@ -25,7 +87,7 @@ class Organizations extends Client {
2587 /**
2688 * Lists organizations associated with a specific user.
2789 * @param {number } userID - The ID of the user.
28- * @returns {Promise<object []> } List of organizations associated with the user.
90+ * @returns {Promise<Organization []> } List of organizations associated with the user.
2991 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#list-organizations }
3092 * @example const userOrgs = await client.organizations.listByUser(12345);
3193 */
@@ -64,7 +126,7 @@ class Organizations extends Client {
64126 /**
65127 * Retrieves related information for a specific organization.
66128 * @param {number } organizationID - The ID of the organization.
67- * @returns {Promise<{response: object, result: object }> } Object containing related information of the organization.
129+ * @returns {Promise<{response: object, result: OrganizationRelatedResponse }> } Object containing related information of the organization.
68130 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organizations-related-information }
69131 * @example const relatedInfo = await client.organizations.related(12345);
70132 */
@@ -75,7 +137,7 @@ class Organizations extends Client {
75137 /**
76138 * Views a specific organization by its ID.
77139 * @param {number } organizationID - The ID of the organization.
78- * @returns {Promise<{response: object, result: object }> } The organization's details.
140+ * @returns {Promise<{response: object, result: Organization }> } The organization's details.
79141 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organization }
80142 * @example const organization = await client.organizations.show(12345);
81143 */
@@ -86,7 +148,7 @@ class Organizations extends Client {
86148 /**
87149 * Retrieves details of multiple organizations based on their IDs.
88150 * @param {number[] } organizationIDs - Array of organization IDs.
89- * @returns {Promise<object []> } List of organizations' details.
151+ * @returns {Promise<Organization []> } List of organizations' details.
90152 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-many-organizations }
91153 * @example const orgDetails = await client.organizations.showMany([12345, 67890]);
92154 */
@@ -103,7 +165,7 @@ class Organizations extends Client {
103165 /**
104166 * Retrieves details of multiple organizations based on their External IDs.
105167 * @param {string[] } externalOrganizationIds - Array of organization IDs.
106- * @returns {Promise<object []> } List of organizations' details.
168+ * @returns {Promise<Organization []> } List of organizations' details.
107169 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-many-organizations }
108170 * @example const orgDetails = await client.organizations.showMany(['12345', '67890']);
109171 */
@@ -119,32 +181,32 @@ class Organizations extends Client {
119181
120182 /**
121183 * 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.
184+ * @param {CreateOrganization } organization - The organization object to create.
185+ * @returns {Promise<{response: object, result: Organization }> } The created organization's details.
124186 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-organization }
125- * @example const newOrganization = await client.organizations.create({ name: 'New Org' });
187+ * @example const newOrganization = await client.organizations.create({ organization: { name: 'New Org' } });
126188 */
127189 async create ( organization ) {
128190 return this . post ( [ 'organizations' ] , organization ) ;
129191 }
130192
131193 /**
132194 * 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.
195+ * @param {CreateManyOrganizations } organizations - An array of organization objects to create.
196+ * @returns {Promise<{response: object, result: Organization []}> } Details of the created organizations.
135197 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-many-organizations }
136- * @example const newOrganizations = await client.organizations.createMany([{ name: 'Org1' }, { name: 'Org2' }]);
198+ * @example const newOrganizations = await client.organizations.createMany({ organizations: [{ name: 'Org1' }, { name: 'Org2' }] } );
137199 */
138200 async createMany ( organizations ) {
139201 return this . post ( [ 'organizations' , 'create_many' ] , organizations ) ;
140202 }
141203
142204 /**
143205 * 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.
206+ * @param {CreateOrganization|UpdateOrganizationWithId } organization - The organization object to create or update.
207+ * @returns {Promise<{response: object, result: Organization }> } The created or updated organization's details.
146208 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-or-update-organization }
147- * @example const org = await client.organizations.createOrUpdate({ id: 12345, name: 'Updated Name' });
209+ * @example const org = await client.organizations.createOrUpdate({ organization: { id: 12345, name: 'Updated Name' } });
148210 */
149211 async createOrUpdate ( organization ) {
150212 return this . post ( [ 'organizations' , 'create_or_update' ] , organization ) ;
@@ -153,35 +215,36 @@ class Organizations extends Client {
153215 /**
154216 * Updates a specific organization by its ID.
155217 * @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.
218+ * @param {UpdateOrganization } organization - The updated organization object.
219+ * @returns {Promise<{response: object, result: Organization }> } The updated organization's details.
158220 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#update-organization }
159- * @example const updatedOrganization = await client.organizations.update(12345, { name: 'New Name' });
221+ * @example const updatedOrganization = await client.organizations.update(12345, { organization: { name: 'New Name' } });
160222 */
161223 async update ( organizationID , organization ) {
162224 return this . put ( [ 'organizations' , organizationID ] , organization ) ;
163225 }
164226
165227 /**
166228 * 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.
229+ * @param {UpdateManyOrganizations } organizations - An array of organization objects to update.
230+ * @returns {Promise<{response: object, result: Organization []}> } Details of the updated organizations.
169231 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#update-many-organizations }
170- * @example const updatedOrganizations = await client.organizations.updateMany([{ id: 1, name: 'Updated Org1' }, { id: 2, name: 'Updated Org2' }]);
232+ * @example const updatedOrganizations = await client.organizations.updateMany({ organizations: [{ id: 1, name: 'Updated Org1' }, { id: 2, name: 'Updated Org2' }] } );
171233 */
172234 async updateMany ( organizations ) {
173235 return this . put ( [ 'organizations' , 'update_many' ] , organizations ) ;
174236 }
175237
176238 /**
177- * 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.
239+ * Creates or updates an organization, identical to `createOrUpdate` method.
240+ * @param {CreateOrganization|UpdateOrganizationWithId } organization - The organization object to upsert.
241+ * @returns {Promise<{response: object, result: Organization }> } The created or updated organization's details.
180242 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-or-update-organization }
181- * @example const org = await client.organizations.upsert({ id: 12345, name: 'Upserted Name' });
243+ * @example const org = await client.organizations.upsert({ organization: { id: 12345, name: 'Upserted Name' }});
244+ * @deprecated use `createOrUpdate()` method instead.
182245 */
183246 async upsert ( organization ) {
184- return this . post ( [ 'organizations' , 'create_or_update' ] , organization ) ;
247+ return this . createOrUpdate ( organization ) ;
185248 }
186249
187250 /**
@@ -235,7 +298,7 @@ class Organizations extends Client {
235298 /**
236299 * Searches organizations based on external ID.
237300 * @param {number } externalID - Search by externalID.
238- * @returns {Promise<object []> } List of organizations matching the search.
301+ * @returns {Promise<Organization []> } List of organizations matching the search.
239302 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#search-organizations-by-external-id }
240303 * @example const foundOrganizations = await client.organizations.search(1234);
241304 */
@@ -246,7 +309,7 @@ class Organizations extends Client {
246309 /**
247310 * Autocompletes organization names based on provided parameters.
248311 * @param {object } parameters - Parameters for autocomplete.
249- * @returns {Promise<object []> } List of organizations matching the autocomplete.
312+ * @returns {Promise<Organization []> } List of organizations matching the autocomplete.
250313 * @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#autocomplete-organizations }
251314 * @example const autocompleteResults = await client.organizations.autocomplete({ name: 'Test' });
252315 */
@@ -258,7 +321,7 @@ class Organizations extends Client {
258321 * Incrementally exports organizations with an include parameter.
259322 * @param {string|Date } startTime - Start time for incremental export.
260323 * @param {string } include - Data to include in the export.
261- * @returns {Promise<object []> } List of organizations in the incremental export.
324+ * @returns {Promise<Organization []> } List of organizations in the incremental export.
262325 * @see {@link https://developer.zendesk.com/api-reference/ticketing/ticket-management/incremental_exports/#incremental-organization-export }
263326 * @example const exportedOrganizations = await client.organizations.incrementalInclude('2023-01-01T12:00:00Z', 'users');
264327 */
@@ -273,7 +336,7 @@ class Organizations extends Client {
273336 /**
274337 * Incrementally exports organizations.
275338 * @param {string|Date } startTime - Start time for incremental export.
276- * @returns {Promise<object []> } List of organizations in the incremental export.
339+ * @returns {Promise<Organization []> } List of organizations in the incremental export.
277340 * @see {@link https://developer.zendesk.com/api-reference/ticketing/ticket-management/incremental_exports/#incremental-organization-export }
278341 * @example const exportedOrganizations = await client.organizations.incremental('2023-01-01T12:00:00Z');
279342 */
@@ -288,7 +351,7 @@ class Organizations extends Client {
288351 /**
289352 * Fetches a sample of incremental organization exports.
290353 * @param {string|Date } startTime - Start time for the sample.
291- * @returns {Promise<{response: object, result: object []}> } Sample list of organizations in the incremental export.
354+ * @returns {Promise<{response: object, result: Organization []}> } Sample list of organizations in the incremental export.
292355 * @see {@link https://developer.zendesk.com/api-reference/ticketing/ticket-management/incremental_exports/#incremental-sample-export }
293356 * @example const sampleExportedOrganizations = await client.organizations.incrementalSample('2023-01-01T12:00:00Z');
294357 */
0 commit comments