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 {{
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
+
4
66
/**
5
67
* @class
6
68
* Client for interacting with the Zendesk Organizations API.
@@ -14,7 +76,7 @@ class Organizations extends Client {
14
76
15
77
/**
16
78
* Lists all organizations.
17
- * @returns {Promise<object > } The list of organizations.
79
+ * @returns {Promise<Organization[] > } The list of organizations.
18
80
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#list-organizations }
19
81
* @example const organizations = await client.organizations.list();
20
82
*/
@@ -25,7 +87,7 @@ class Organizations extends Client {
25
87
/**
26
88
* Lists organizations associated with a specific user.
27
89
* @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.
29
91
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#list-organizations }
30
92
* @example const userOrgs = await client.organizations.listByUser(12345);
31
93
*/
@@ -64,7 +126,7 @@ class Organizations extends Client {
64
126
/**
65
127
* Retrieves related information for a specific organization.
66
128
* @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.
68
130
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organizations-related-information }
69
131
* @example const relatedInfo = await client.organizations.related(12345);
70
132
*/
@@ -75,7 +137,7 @@ class Organizations extends Client {
75
137
/**
76
138
* Views a specific organization by its ID.
77
139
* @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.
79
141
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organization }
80
142
* @example const organization = await client.organizations.show(12345);
81
143
*/
@@ -86,7 +148,7 @@ class Organizations extends Client {
86
148
/**
87
149
* Retrieves details of multiple organizations based on their IDs.
88
150
* @param {number[] } organizationIDs - Array of organization IDs.
89
- * @returns {Promise<object []> } List of organizations' details.
151
+ * @returns {Promise<Organization []> } List of organizations' details.
90
152
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-many-organizations }
91
153
* @example const orgDetails = await client.organizations.showMany([12345, 67890]);
92
154
*/
@@ -103,7 +165,7 @@ class Organizations extends Client {
103
165
/**
104
166
* Retrieves details of multiple organizations based on their External IDs.
105
167
* @param {string[] } externalOrganizationIds - Array of organization IDs.
106
- * @returns {Promise<object []> } List of organizations' details.
168
+ * @returns {Promise<Organization []> } List of organizations' details.
107
169
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-many-organizations }
108
170
* @example const orgDetails = await client.organizations.showMany(['12345', '67890']);
109
171
*/
@@ -119,32 +181,32 @@ class Organizations extends Client {
119
181
120
182
/**
121
183
* 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.
124
186
* @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' } });
126
188
*/
127
189
async create ( organization ) {
128
190
return this . post ( [ 'organizations' ] , organization ) ;
129
191
}
130
192
131
193
/**
132
194
* 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.
135
197
* @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' }] } );
137
199
*/
138
200
async createMany ( organizations ) {
139
201
return this . post ( [ 'organizations' , 'create_many' ] , organizations ) ;
140
202
}
141
203
142
204
/**
143
205
* 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.
146
208
* @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' } });
148
210
*/
149
211
async createOrUpdate ( organization ) {
150
212
return this . post ( [ 'organizations' , 'create_or_update' ] , organization ) ;
@@ -153,35 +215,36 @@ class Organizations extends Client {
153
215
/**
154
216
* Updates a specific organization by its ID.
155
217
* @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.
158
220
* @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' } });
160
222
*/
161
223
async update ( organizationID , organization ) {
162
224
return this . put ( [ 'organizations' , organizationID ] , organization ) ;
163
225
}
164
226
165
227
/**
166
228
* 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.
169
231
* @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' }] } );
171
233
*/
172
234
async updateMany ( organizations ) {
173
235
return this . put ( [ 'organizations' , 'update_many' ] , organizations ) ;
174
236
}
175
237
176
238
/**
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.
180
242
* @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.
182
245
*/
183
246
async upsert ( organization ) {
184
- return this . post ( [ 'organizations' , 'create_or_update' ] , organization ) ;
247
+ return this . createOrUpdate ( organization ) ;
185
248
}
186
249
187
250
/**
@@ -235,7 +298,7 @@ class Organizations extends Client {
235
298
/**
236
299
* Searches organizations based on external ID.
237
300
* @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.
239
302
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#search-organizations-by-external-id }
240
303
* @example const foundOrganizations = await client.organizations.search(1234);
241
304
*/
@@ -246,7 +309,7 @@ class Organizations extends Client {
246
309
/**
247
310
* Autocompletes organization names based on provided parameters.
248
311
* @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.
250
313
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#autocomplete-organizations }
251
314
* @example const autocompleteResults = await client.organizations.autocomplete({ name: 'Test' });
252
315
*/
@@ -258,7 +321,7 @@ class Organizations extends Client {
258
321
* Incrementally exports organizations with an include parameter.
259
322
* @param {string|Date } startTime - Start time for incremental export.
260
323
* @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.
262
325
* @see {@link https://developer.zendesk.com/api-reference/ticketing/ticket-management/incremental_exports/#incremental-organization-export }
263
326
* @example const exportedOrganizations = await client.organizations.incrementalInclude('2023-01-01T12:00:00Z', 'users');
264
327
*/
@@ -273,7 +336,7 @@ class Organizations extends Client {
273
336
/**
274
337
* Incrementally exports organizations.
275
338
* @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.
277
340
* @see {@link https://developer.zendesk.com/api-reference/ticketing/ticket-management/incremental_exports/#incremental-organization-export }
278
341
* @example const exportedOrganizations = await client.organizations.incremental('2023-01-01T12:00:00Z');
279
342
*/
@@ -288,7 +351,7 @@ class Organizations extends Client {
288
351
/**
289
352
* Fetches a sample of incremental organization exports.
290
353
* @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.
292
355
* @see {@link https://developer.zendesk.com/api-reference/ticketing/ticket-management/incremental_exports/#incremental-sample-export }
293
356
* @example const sampleExportedOrganizations = await client.organizations.incrementalSample('2023-01-01T12:00:00Z');
294
357
*/
0 commit comments