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'> } 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
+
4
42
/**
5
43
* @class
6
44
* Client for interacting with the Zendesk Organizations API.
@@ -14,7 +52,7 @@ class Organizations extends Client {
14
52
15
53
/**
16
54
* Lists all organizations.
17
- * @returns {Promise<object > } The list of organizations.
55
+ * @returns {Promise<Organization[] > } The list of organizations.
18
56
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#list-organizations }
19
57
* @example const organizations = await client.organizations.list();
20
58
*/
@@ -25,7 +63,7 @@ class Organizations extends Client {
25
63
/**
26
64
* Lists organizations associated with a specific user.
27
65
* @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.
29
67
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#list-organizations }
30
68
* @example const userOrgs = await client.organizations.listByUser(12345);
31
69
*/
@@ -64,7 +102,7 @@ class Organizations extends Client {
64
102
/**
65
103
* Retrieves related information for a specific organization.
66
104
* @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.
68
106
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organizations-related-information }
69
107
* @example const relatedInfo = await client.organizations.related(12345);
70
108
*/
@@ -75,7 +113,7 @@ class Organizations extends Client {
75
113
/**
76
114
* Views a specific organization by its ID.
77
115
* @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.
79
117
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organization }
80
118
* @example const organization = await client.organizations.show(12345);
81
119
*/
@@ -86,7 +124,7 @@ class Organizations extends Client {
86
124
/**
87
125
* Retrieves details of multiple organizations based on their IDs.
88
126
* @param {number[] } organizationIDs - Array of organization IDs.
89
- * @returns {Promise<object []> } List of organizations' details.
127
+ * @returns {Promise<Organization []> } List of organizations' details.
90
128
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-many-organizations }
91
129
* @example const orgDetails = await client.organizations.showMany([12345, 67890]);
92
130
*/
@@ -103,7 +141,7 @@ class Organizations extends Client {
103
141
/**
104
142
* Retrieves details of multiple organizations based on their External IDs.
105
143
* @param {string[] } externalOrganizationIds - Array of organization IDs.
106
- * @returns {Promise<object []> } List of organizations' details.
144
+ * @returns {Promise<Organization []> } List of organizations' details.
107
145
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-many-organizations }
108
146
* @example const orgDetails = await client.organizations.showMany(['12345', '67890']);
109
147
*/
@@ -119,64 +157,64 @@ class Organizations extends Client {
119
157
120
158
/**
121
159
* 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.
124
162
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-organization }
125
163
* @example const newOrganization = await client.organizations.create({ name: 'New Org' });
126
164
*/
127
165
async create ( organization ) {
128
- return this . post ( [ 'organizations' ] , organization ) ;
166
+ return this . post ( [ 'organizations' ] , { organization} ) ;
129
167
}
130
168
131
169
/**
132
170
* 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.
135
173
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-many-organizations }
136
174
* @example const newOrganizations = await client.organizations.createMany([{ name: 'Org1' }, { name: 'Org2' }]);
137
175
*/
138
176
async createMany ( organizations ) {
139
- return this . post ( [ 'organizations' , 'create_many' ] , organizations ) ;
177
+ return this . post ( [ 'organizations' , 'create_many' ] , { organizations} ) ;
140
178
}
141
179
142
180
/**
143
181
* 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.
146
184
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-or-update-organization }
147
185
* @example const org = await client.organizations.createOrUpdate({ id: 12345, name: 'Updated Name' });
148
186
*/
149
187
async createOrUpdate ( organization ) {
150
- return this . post ( [ 'organizations' , 'create_or_update' ] , organization ) ;
188
+ return this . post ( [ 'organizations' , 'create_or_update' ] , { organization} ) ;
151
189
}
152
190
153
191
/**
154
192
* Updates a specific organization by its ID.
155
193
* @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.
158
196
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#update-organization }
159
197
* @example const updatedOrganization = await client.organizations.update(12345, { name: 'New Name' });
160
198
*/
161
199
async update ( organizationID , organization ) {
162
- return this . put ( [ 'organizations' , organizationID ] , organization ) ;
200
+ return this . put ( [ 'organizations' , organizationID ] , { organization} ) ;
163
201
}
164
202
165
203
/**
166
204
* 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.
169
207
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#update-many-organizations }
170
208
* @example const updatedOrganizations = await client.organizations.updateMany([{ id: 1, name: 'Updated Org1' }, { id: 2, name: 'Updated Org2' }]);
171
209
*/
172
210
async updateMany ( organizations ) {
173
- return this . put ( [ 'organizations' , 'update_many' ] , organizations ) ;
211
+ return this . put ( [ 'organizations' , 'update_many' ] , { organizations} ) ;
174
212
}
175
213
176
214
/**
177
215
* 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.
180
218
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#create-or-update-organization }
181
219
* @example const org = await client.organizations.upsert({ id: 12345, name: 'Upserted Name' });
182
220
*/
@@ -235,7 +273,7 @@ class Organizations extends Client {
235
273
/**
236
274
* Searches organizations based on external ID.
237
275
* @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.
239
277
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#search-organizations-by-external-id }
240
278
* @example const foundOrganizations = await client.organizations.search(1234);
241
279
*/
@@ -246,7 +284,7 @@ class Organizations extends Client {
246
284
/**
247
285
* Autocompletes organization names based on provided parameters.
248
286
* @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.
250
288
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#autocomplete-organizations }
251
289
* @example const autocompleteResults = await client.organizations.autocomplete({ name: 'Test' });
252
290
*/
@@ -258,7 +296,7 @@ class Organizations extends Client {
258
296
* Incrementally exports organizations with an include parameter.
259
297
* @param {string|Date } startTime - Start time for incremental export.
260
298
* @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.
262
300
* @see {@link https://developer.zendesk.com/api-reference/ticketing/ticket-management/incremental_exports/#incremental-organization-export }
263
301
* @example const exportedOrganizations = await client.organizations.incrementalInclude('2023-01-01T12:00:00Z', 'users');
264
302
*/
@@ -273,7 +311,7 @@ class Organizations extends Client {
273
311
/**
274
312
* Incrementally exports organizations.
275
313
* @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.
277
315
* @see {@link https://developer.zendesk.com/api-reference/ticketing/ticket-management/incremental_exports/#incremental-organization-export }
278
316
* @example const exportedOrganizations = await client.organizations.incremental('2023-01-01T12:00:00Z');
279
317
*/
@@ -288,7 +326,7 @@ class Organizations extends Client {
288
326
/**
289
327
* Fetches a sample of incremental organization exports.
290
328
* @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.
292
330
* @see {@link https://developer.zendesk.com/api-reference/ticketing/ticket-management/incremental_exports/#incremental-sample-export }
293
331
* @example const sampleExportedOrganizations = await client.organizations.incrementalSample('2023-01-01T12:00:00Z');
294
332
*/
0 commit comments