1
1
// File: organizations.js
2
2
const { Client} = require ( '../client' ) ;
3
3
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'> } CreateOrganization
25
+ */
26
+
27
+ /**
28
+ * @typedef {object } CreateManyOrganizations
29
+ * @property {CreateOrganization[] } [organizations] - The organization object to create many organizations.
30
+ */
31
+
32
+ /**
33
+ * @typedef {Partial<Omit<Organization, 'created_at' | 'updated_at' | 'url'>> } UpdateOrganization
34
+ */
35
+
36
+ /**
37
+ * @typedef {object } UpdateManyOrganizations
38
+ * @property {UpdateOrganization[] } [organizations] - The organization object to update many organizations.
39
+ */
40
+
41
+ /**
42
+ * @typedef {object } OrganizationRelatedResponse
43
+ * @property {object } organization_related - Information about objects related to the organization.
44
+ * @property {number } organization_related.tickets_count - The number of tickets related to the organization.
45
+ * @property {number } organization_related.users_count - The number of users related to the organization.
46
+ */
47
+
4
48
/**
5
49
* @class
6
50
* Client for interacting with the Zendesk Organizations API.
@@ -14,7 +58,7 @@ class Organizations extends Client {
14
58
15
59
/**
16
60
* Lists all organizations.
17
- * @returns {Promise<object > } The list of organizations.
61
+ * @returns {Promise<Organization[] > } The list of organizations.
18
62
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#list-organizations }
19
63
* @example const organizations = await client.organizations.list();
20
64
*/
@@ -25,7 +69,7 @@ class Organizations extends Client {
25
69
/**
26
70
* Lists organizations associated with a specific user.
27
71
* @param {number } userID - The ID of the user.
28
- * @returns {Promise<object []> } List of organizations associated with the user.
72
+ * @returns {Promise<Organization []> } List of organizations associated with the user.
29
73
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#list-organizations }
30
74
* @example const userOrgs = await client.organizations.listByUser(12345);
31
75
*/
@@ -64,7 +108,7 @@ class Organizations extends Client {
64
108
/**
65
109
* Retrieves related information for a specific organization.
66
110
* @param {number } organizationID - The ID of the organization.
67
- * @returns {Promise<{response: object, result: object }> } Object containing related information of the organization.
111
+ * @returns {Promise<{response: object, result: OrganizationRelatedResponse }> } Object containing related information of the organization.
68
112
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organizations-related-information }
69
113
* @example const relatedInfo = await client.organizations.related(12345);
70
114
*/
@@ -75,7 +119,7 @@ class Organizations extends Client {
75
119
/**
76
120
* Views a specific organization by its ID.
77
121
* @param {number } organizationID - The ID of the organization.
78
- * @returns {Promise<{response: object, result: object }> } The organization's details.
122
+ * @returns {Promise<{response: object, result: Organization }> } The organization's details.
79
123
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organization }
80
124
* @example const organization = await client.organizations.show(12345);
81
125
*/
@@ -86,7 +130,7 @@ class Organizations extends Client {
86
130
/**
87
131
* Retrieves details of multiple organizations based on their IDs.
88
132
* @param {number[] } organizationIDs - Array of organization IDs.
89
- * @returns {Promise<object []> } List of organizations' details.
133
+ * @returns {Promise<Organization []> } List of organizations' details.
90
134
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-many-organizations }
91
135
* @example const orgDetails = await client.organizations.showMany([12345, 67890]);
92
136
*/
@@ -103,7 +147,7 @@ class Organizations extends Client {
103
147
/**
104
148
* Retrieves details of multiple organizations based on their External IDs.
105
149
* @param {string[] } externalOrganizationIds - Array of organization IDs.
106
- * @returns {Promise<object []> } List of organizations' details.
150
+ * @returns {Promise<Organization []> } List of organizations' details.
107
151
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-many-organizations }
108
152
* @example const orgDetails = await client.organizations.showMany(['12345', '67890']);
109
153
*/
@@ -119,8 +163,8 @@ class Organizations extends Client {
119
163
120
164
/**
121
165
* 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.
166
+ * @param {CreateOrganization } organization - The organization object to create.
167
+ * @returns {Promise<{response: object, result: Organization }> } The created organization's details.
124
168
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-organization }
125
169
* @example const newOrganization = await client.organizations.create({ name: 'New Org' });
126
170
*/
@@ -130,19 +174,19 @@ class Organizations extends Client {
130
174
131
175
/**
132
176
* 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.
177
+ * @param {CreateManyOrganizations } organizations - An array of organization objects to create.
178
+ * @returns {Promise<{response: object, result: Organization []}> } Details of the created organizations.
135
179
* @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' }]);
180
+ * @example const newOrganizations = await client.organizations.createMany({ organizations: [{ name: 'Org1' }, { name: 'Org2' }] } );
137
181
*/
138
182
async createMany ( organizations ) {
139
183
return this . post ( [ 'organizations' , 'create_many' ] , organizations ) ;
140
184
}
141
185
142
186
/**
143
187
* 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.
188
+ * @param {CreateOrganization|UpdateOrganization } organization - The organization object to create or update.
189
+ * @returns {Promise<{response: object, result: Organization }> } The created or updated organization's details.
146
190
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-or-update-organization }
147
191
* @example const org = await client.organizations.createOrUpdate({ id: 12345, name: 'Updated Name' });
148
192
*/
@@ -153,8 +197,8 @@ class Organizations extends Client {
153
197
/**
154
198
* Updates a specific organization by its ID.
155
199
* @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.
200
+ * @param {Omit<UpdateOrganization, 'id'> } organization - The updated organization object.
201
+ * @returns {Promise<{response: object, result: Organization }> } The updated organization's details.
158
202
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#update-organization }
159
203
* @example const updatedOrganization = await client.organizations.update(12345, { name: 'New Name' });
160
204
*/
@@ -164,19 +208,19 @@ class Organizations extends Client {
164
208
165
209
/**
166
210
* 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.
211
+ * @param {UpdateManyOrganizations } organizations - An array of organization objects to update.
212
+ * @returns {Promise<{response: object, result: Organization []}> } Details of the updated organizations.
169
213
* @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' }]);
214
+ * @example const updatedOrganizations = await client.organizations.updateMany({ organizations: [{ id: 1, name: 'Updated Org1' }, { id: 2, name: 'Updated Org2' }] } );
171
215
*/
172
216
async updateMany ( organizations ) {
173
217
return this . put ( [ 'organizations' , 'update_many' ] , organizations ) ;
174
218
}
175
219
176
220
/**
177
221
* 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.
222
+ * @param {UpdateOrganization|CreateOrganization } organization - The organization object to upsert.
223
+ * @returns {Promise<{response: object, result: Organization }> } The created or updated organization's details.
180
224
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-or-update-organization }
181
225
* @example const org = await client.organizations.upsert({ id: 12345, name: 'Upserted Name' });
182
226
*/
@@ -235,7 +279,7 @@ class Organizations extends Client {
235
279
/**
236
280
* Searches organizations based on external ID.
237
281
* @param {number } externalID - Search by externalID.
238
- * @returns {Promise<object []> } List of organizations matching the search.
282
+ * @returns {Promise<Organization []> } List of organizations matching the search.
239
283
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#search-organizations-by-external-id }
240
284
* @example const foundOrganizations = await client.organizations.search(1234);
241
285
*/
@@ -246,7 +290,7 @@ class Organizations extends Client {
246
290
/**
247
291
* Autocompletes organization names based on provided parameters.
248
292
* @param {object } parameters - Parameters for autocomplete.
249
- * @returns {Promise<object []> } List of organizations matching the autocomplete.
293
+ * @returns {Promise<Organization []> } List of organizations matching the autocomplete.
250
294
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#autocomplete-organizations }
251
295
* @example const autocompleteResults = await client.organizations.autocomplete({ name: 'Test' });
252
296
*/
@@ -258,7 +302,7 @@ class Organizations extends Client {
258
302
* Incrementally exports organizations with an include parameter.
259
303
* @param {string|Date } startTime - Start time for incremental export.
260
304
* @param {string } include - Data to include in the export.
261
- * @returns {Promise<object []> } List of organizations in the incremental export.
305
+ * @returns {Promise<Organization []> } List of organizations in the incremental export.
262
306
* @see {@link https://developer.zendesk.com/api-reference/ticketing/ticket-management/incremental_exports/#incremental-organization-export }
263
307
* @example const exportedOrganizations = await client.organizations.incrementalInclude('2023-01-01T12:00:00Z', 'users');
264
308
*/
@@ -273,7 +317,7 @@ class Organizations extends Client {
273
317
/**
274
318
* Incrementally exports organizations.
275
319
* @param {string|Date } startTime - Start time for incremental export.
276
- * @returns {Promise<object []> } List of organizations in the incremental export.
320
+ * @returns {Promise<Organization []> } List of organizations in the incremental export.
277
321
* @see {@link https://developer.zendesk.com/api-reference/ticketing/ticket-management/incremental_exports/#incremental-organization-export }
278
322
* @example const exportedOrganizations = await client.organizations.incremental('2023-01-01T12:00:00Z');
279
323
*/
@@ -288,7 +332,7 @@ class Organizations extends Client {
288
332
/**
289
333
* Fetches a sample of incremental organization exports.
290
334
* @param {string|Date } startTime - Start time for the sample.
291
- * @returns {Promise<{response: object, result: object []}> } Sample list of organizations in the incremental export.
335
+ * @returns {Promise<{response: object, result: Organization []}> } Sample list of organizations in the incremental export.
292
336
* @see {@link https://developer.zendesk.com/api-reference/ticketing/ticket-management/incremental_exports/#incremental-sample-export }
293
337
* @example const sampleExportedOrganizations = await client.organizations.incrementalSample('2023-01-01T12:00:00Z');
294
338
*/
0 commit comments