How to use doFetch method in wpt

Best JavaScript code snippet using wpt

client4.ts

Source:client4.ts Github

copy

Full Screen

...799 {method: 'put', body: JSON.stringify(status)},800 );801 };802 updateCustomStatus = (customStatus: UserCustomStatus) => {803 return this.doFetch(804 `${this.getUserRoute('me')}/status/custom`,805 {method: 'put', body: JSON.stringify(customStatus)},806 );807 };808 unsetCustomStatus = () => {809 return this.doFetch(810 `${this.getUserRoute('me')}/status/custom`,811 {method: 'delete'},812 );813 }814 removeRecentCustomStatus = (customStatus: UserCustomStatus) => {815 return this.doFetch(816 `${this.getUserRoute('me')}/status/custom/recent`,817 {method: 'delete', body: JSON.stringify(customStatus)},818 );819 }820 switchEmailToOAuth = (service: string, email: string, password: string, mfaCode = '') => {821 this.trackEvent('api', 'api_users_email_to_oauth');822 return this.doFetch<AuthChangeResponse>(823 `${this.getUsersRoute()}/login/switch`,824 {method: 'post', body: JSON.stringify({current_service: 'email', new_service: service, email, password, mfa_code: mfaCode})},825 );826 };827 switchOAuthToEmail = (currentService: string, email: string, password: string) => {828 this.trackEvent('api', 'api_users_oauth_to_email');829 return this.doFetch<AuthChangeResponse>(830 `${this.getUsersRoute()}/login/switch`,831 {method: 'post', body: JSON.stringify({current_service: currentService, new_service: 'email', email, new_password: password})},832 );833 };834 switchEmailToLdap = (email: string, emailPassword: string, ldapId: string, ldapPassword: string, mfaCode = '') => {835 this.trackEvent('api', 'api_users_email_to_ldap');836 return this.doFetch<AuthChangeResponse>(837 `${this.getUsersRoute()}/login/switch`,838 {method: 'post', body: JSON.stringify({current_service: 'email', new_service: 'ldap', email, password: emailPassword, ldap_id: ldapId, new_password: ldapPassword, mfa_code: mfaCode})},839 );840 };841 switchLdapToEmail = (ldapPassword: string, email: string, emailPassword: string, mfaCode = '') => {842 this.trackEvent('api', 'api_users_ldap_to_email');843 return this.doFetch<AuthChangeResponse>(844 `${this.getUsersRoute()}/login/switch`,845 {method: 'post', body: JSON.stringify({current_service: 'ldap', new_service: 'email', email, password: ldapPassword, new_password: emailPassword, mfa_code: mfaCode})},846 );847 };848 getAuthorizedOAuthApps = (userId: string) => {849 return this.doFetch<OAuthApp[]>(850 `${this.getUserRoute(userId)}/oauth/apps/authorized`,851 {method: 'get'},852 );853 }854 authorizeOAuthApp = (responseType: string, clientId: string, redirectUri: string, state: string, scope: string) => {855 return this.doFetch<void>(856 `${this.url}/oauth/authorize`,857 {method: 'post', body: JSON.stringify({client_id: clientId, response_type: responseType, redirect_uri: redirectUri, state, scope})},858 );859 }860 deauthorizeOAuthApp = (clientId: string) => {861 return this.doFetch<StatusOK>(862 `${this.url}/oauth/deauthorize`,863 {method: 'post', body: JSON.stringify({client_id: clientId})},864 );865 }866 createUserAccessToken = (userId: string, description: string) => {867 this.trackEvent('api', 'api_users_create_access_token');868 return this.doFetch<UserAccessToken>(869 `${this.getUserRoute(userId)}/tokens`,870 {method: 'post', body: JSON.stringify({description})},871 );872 }873 getUserAccessToken = (tokenId: string) => {874 return this.doFetch<UserAccessToken>(875 `${this.getUsersRoute()}/tokens/${tokenId}`,876 {method: 'get'},877 );878 }879 getUserAccessTokensForUser = (userId: string, page = 0, perPage = PER_PAGE_DEFAULT) => {880 return this.doFetch<UserAccessToken[]>(881 `${this.getUserRoute(userId)}/tokens${buildQueryString({page, per_page: perPage})}`,882 {method: 'get'},883 );884 }885 getUserAccessTokens = (page = 0, perPage = PER_PAGE_DEFAULT) => {886 return this.doFetch<UserAccessToken[]>(887 `${this.getUsersRoute()}/tokens${buildQueryString({page, per_page: perPage})}`,888 {method: 'get'},889 );890 }891 revokeUserAccessToken = (tokenId: string) => {892 this.trackEvent('api', 'api_users_revoke_access_token');893 return this.doFetch<StatusOK>(894 `${this.getUsersRoute()}/tokens/revoke`,895 {method: 'post', body: JSON.stringify({token_id: tokenId})},896 );897 }898 disableUserAccessToken = (tokenId: string) => {899 return this.doFetch<StatusOK>(900 `${this.getUsersRoute()}/tokens/disable`,901 {method: 'post', body: JSON.stringify({token_id: tokenId})},902 );903 }904 enableUserAccessToken = (tokenId: string) => {905 return this.doFetch<StatusOK>(906 `${this.getUsersRoute()}/tokens/enable`,907 {method: 'post', body: JSON.stringify({token_id: tokenId})},908 );909 }910 // Team Routes911 createTeam = (team: Team) => {912 this.trackEvent('api', 'api_teams_create');913 return this.doFetch<Team>(914 `${this.getTeamsRoute()}`,915 {method: 'post', body: JSON.stringify(team)},916 );917 };918 deleteTeam = (teamId: string) => {919 this.trackEvent('api', 'api_teams_delete');920 return this.doFetch<StatusOK>(921 `${this.getTeamRoute(teamId)}`,922 {method: 'delete'},923 );924 };925 updateTeam = (team: Team) => {926 this.trackEvent('api', 'api_teams_update_name', {team_id: team.id});927 return this.doFetch<Team>(928 `${this.getTeamRoute(team.id)}`,929 {method: 'put', body: JSON.stringify(team)},930 );931 };932 patchTeam = (team: Partial<Team> & {id: string}) => {933 this.trackEvent('api', 'api_teams_patch_name', {team_id: team.id});934 return this.doFetch<Team>(935 `${this.getTeamRoute(team.id)}/patch`,936 {method: 'put', body: JSON.stringify(team)},937 );938 };939 regenerateTeamInviteId = (teamId: string) => {940 this.trackEvent('api', 'api_teams_regenerate_invite_id', {team_id: teamId});941 return this.doFetch<Team>(942 `${this.getTeamRoute(teamId)}/regenerate_invite_id`,943 {method: 'post'},944 );945 };946 updateTeamScheme = (teamId: string, schemeId: string) => {947 const patch = {scheme_id: schemeId};948 this.trackEvent('api', 'api_teams_update_scheme', {team_id: teamId, ...patch});949 return this.doFetch<StatusOK>(950 `${this.getTeamSchemeRoute(teamId)}`,951 {method: 'put', body: JSON.stringify(patch)},952 );953 };954 checkIfTeamExists = (teamName: string) => {955 return this.doFetch<{exists: boolean}>(956 `${this.getTeamNameRoute(teamName)}/exists`,957 {method: 'get'},958 );959 };960 getTeams = (page = 0, perPage = PER_PAGE_DEFAULT, includeTotalCount = false, excludePolicyConstrained = false) => {961 return this.doFetch<Team[] | TeamsWithCount>(962 `${this.getTeamsRoute()}${buildQueryString({page, per_page: perPage, include_total_count: includeTotalCount, exclude_policy_constrained: excludePolicyConstrained})}`,963 {method: 'get'},964 );965 };966 searchTeams = (term: string, opts: TeamSearchOpts) => {967 this.trackEvent('api', 'api_search_teams');968 return this.doFetch<Team[] | TeamsWithCount>(969 `${this.getTeamsRoute()}/search`,970 {method: 'post', body: JSON.stringify({term, ...opts})},971 );972 };973 getTeam = (teamId: string) => {974 return this.doFetch<Team>(975 this.getTeamRoute(teamId),976 {method: 'get'},977 );978 };979 getTeamByName = (teamName: string) => {980 this.trackEvent('api', 'api_teams_get_team_by_name');981 return this.doFetch<Team>(982 this.getTeamNameRoute(teamName),983 {method: 'get'},984 );985 };986 getMyTeams = () => {987 return this.doFetch<Team[]>(988 `${this.getUserRoute('me')}/teams`,989 {method: 'get'},990 );991 };992 getTeamsForUser = (userId: string) => {993 return this.doFetch<Team[]>(994 `${this.getUserRoute(userId)}/teams`,995 {method: 'get'},996 );997 };998 getMyTeamMembers = () => {999 return this.doFetch<TeamMembership[]>(1000 `${this.getUserRoute('me')}/teams/members`,1001 {method: 'get'},1002 );1003 };1004 getMyTeamUnreads = () => {1005 return this.doFetch<TeamUnread[]>(1006 `${this.getUserRoute('me')}/teams/unread`,1007 {method: 'get'},1008 );1009 };1010 getTeamMembers = (teamId: string, page = 0, perPage = PER_PAGE_DEFAULT, options: GetTeamMembersOpts) => {1011 return this.doFetch<TeamMembership>(1012 `${this.getTeamMembersRoute(teamId)}${buildQueryString({page, per_page: perPage, ...options})}`,1013 {method: 'get'},1014 );1015 };1016 getTeamMembersForUser = (userId: string) => {1017 return this.doFetch<TeamMembership[]>(1018 `${this.getUserRoute(userId)}/teams/members`,1019 {method: 'get'},1020 );1021 };1022 getTeamMember = (teamId: string, userId: string) => {1023 return this.doFetch<TeamMembership>(1024 `${this.getTeamMemberRoute(teamId, userId)}`,1025 {method: 'get'},1026 );1027 };1028 getTeamMembersByIds = (teamId: string, userIds: string[]) => {1029 return this.doFetch<TeamMembership[]>(1030 `${this.getTeamMembersRoute(teamId)}/ids`,1031 {method: 'post', body: JSON.stringify(userIds)},1032 );1033 };1034 addToTeam = (teamId: string, userId: string) => {1035 this.trackEvent('api', 'api_teams_invite_members', {team_id: teamId});1036 const member = {user_id: userId, team_id: teamId};1037 return this.doFetch<TeamMembership>(1038 `${this.getTeamMembersRoute(teamId)}`,1039 {method: 'post', body: JSON.stringify(member)},1040 );1041 };1042 addToTeamFromInvite = (token = '', inviteId = '') => {1043 this.trackEvent('api', 'api_teams_invite_members');1044 const query = buildQueryString({token, invite_id: inviteId});1045 return this.doFetch<TeamMembership>(1046 `${this.getTeamsRoute()}/members/invite${query}`,1047 {method: 'post'},1048 );1049 };1050 addUsersToTeam = (teamId: string, userIds: string[]) => {1051 this.trackEvent('api', 'api_teams_batch_add_members', {team_id: teamId, count: userIds.length});1052 const members: any = [];1053 userIds.forEach((id) => members.push({team_id: teamId, user_id: id}));1054 return this.doFetch<TeamMembership[]>(1055 `${this.getTeamMembersRoute(teamId)}/batch`,1056 {method: 'post', body: JSON.stringify(members)},1057 );1058 };1059 addUsersToTeamGracefully = (teamId: string, userIds: string[]) => {1060 this.trackEvent('api', 'api_teams_batch_add_members', {team_id: teamId, count: userIds.length});1061 const members: any = [];1062 userIds.forEach((id) => members.push({team_id: teamId, user_id: id}));1063 return this.doFetch<TeamMemberWithError[]>(1064 `${this.getTeamMembersRoute(teamId)}/batch?graceful=true`,1065 {method: 'post', body: JSON.stringify(members)},1066 );1067 };1068 joinTeam = (inviteId: string) => {1069 const query = buildQueryString({invite_id: inviteId});1070 return this.doFetch<TeamMembership>(1071 `${this.getTeamsRoute()}/members/invite${query}`,1072 {method: 'post'},1073 );1074 };1075 removeFromTeam = (teamId: string, userId: string) => {1076 this.trackEvent('api', 'api_teams_remove_members', {team_id: teamId});1077 return this.doFetch<StatusOK>(1078 `${this.getTeamMemberRoute(teamId, userId)}`,1079 {method: 'delete'},1080 );1081 };1082 getTeamStats = (teamId: string) => {1083 return this.doFetch<TeamStats>(1084 `${this.getTeamRoute(teamId)}/stats`,1085 {method: 'get'},1086 );1087 };1088 getTotalUsersStats = () => {1089 return this.doFetch<UsersStats>(1090 `${this.getUsersRoute()}/stats`,1091 {method: 'get'},1092 );1093 };1094 getFilteredUsersStats = (options: GetFilteredUsersStatsOpts) => {1095 return this.doFetch<UsersStats>(1096 `${this.getUsersRoute()}/stats/filtered${buildQueryString(options)}`,1097 {method: 'get'},1098 );1099 };1100 invalidateAllEmailInvites = () => {1101 return this.doFetch<StatusOK>(1102 `${this.getTeamsRoute()}/invites/email`,1103 {method: 'delete'},1104 );1105 };1106 getTeamInviteInfo = (inviteId: string) => {1107 return this.doFetch<{1108 display_name: string;1109 description: string;1110 name: string;1111 id: string;1112 }>(1113 `${this.getTeamsRoute()}/invite/${inviteId}`,1114 {method: 'get'},1115 );1116 };1117 updateTeamMemberRoles = (teamId: string, userId: string, roles: string[]) => {1118 this.trackEvent('api', 'api_teams_update_member_roles', {team_id: teamId});1119 return this.doFetch<StatusOK>(1120 `${this.getTeamMemberRoute(teamId, userId)}/roles`,1121 {method: 'put', body: JSON.stringify({roles})},1122 );1123 };1124 sendEmailInvitesToTeam = (teamId: string, emails: string[]) => {1125 this.trackEvent('api', 'api_teams_invite_members', {team_id: teamId});1126 return this.doFetch<StatusOK>(1127 `${this.getTeamRoute(teamId)}/invite/email`,1128 {method: 'post', body: JSON.stringify(emails)},1129 );1130 };1131 sendEmailGuestInvitesToChannels = (teamId: string, channelIds: string[], emails: string[], message: string) => {1132 this.trackEvent('api', 'api_teams_invite_guests', {team_id: teamId, channel_ids: channelIds});1133 return this.doFetch<StatusOK>(1134 `${this.getTeamRoute(teamId)}/invite-guests/email`,1135 {method: 'post', body: JSON.stringify({emails, channels: channelIds, message})},1136 );1137 };1138 sendEmailInvitesToTeamGracefully = (teamId: string, emails: string[]) => {1139 this.trackEvent('api', 'api_teams_invite_members', {team_id: teamId});1140 return this.doFetch<TeamInviteWithError>(1141 `${this.getTeamRoute(teamId)}/invite/email?graceful=true`,1142 {method: 'post', body: JSON.stringify(emails)},1143 );1144 };1145 sendEmailGuestInvitesToChannelsGracefully = async (teamId: string, channelIds: string[], emails: string[], message: string) => {1146 this.trackEvent('api', 'api_teams_invite_guests', {team_id: teamId, channel_ids: channelIds});1147 return this.doFetch<TeamInviteWithError>(1148 `${this.getTeamRoute(teamId)}/invite-guests/email?graceful=true`,1149 {method: 'post', body: JSON.stringify({emails, channels: channelIds, message})},1150 );1151 };1152 importTeam = (teamId: string, file: File, importFrom: string) => {1153 const formData = new FormData();1154 formData.append('file', file, file.name);1155 formData.append('filesize', file.size);1156 formData.append('importFrom', importFrom);1157 const request: any = {1158 method: 'post',1159 body: formData,1160 };1161 if (formData.getBoundary) {1162 request.headers = {1163 'Content-Type': `multipart/form-data; boundary=${formData.getBoundary()}`,1164 };1165 }1166 return this.doFetch<{1167 results: string;1168 }>(1169 `${this.getTeamRoute(teamId)}/import`,1170 request,1171 );1172 };1173 getTeamIconUrl = (teamId: string, lastTeamIconUpdate: number) => {1174 const params: any = {};1175 if (lastTeamIconUpdate) {1176 params._ = lastTeamIconUpdate;1177 }1178 return `${this.getTeamRoute(teamId)}/image${buildQueryString(params)}`;1179 };1180 setTeamIcon = (teamId: string, imageData: File) => {1181 this.trackEvent('api', 'api_team_set_team_icon');1182 const formData = new FormData();1183 formData.append('image', imageData);1184 const request: any = {1185 method: 'post',1186 body: formData,1187 };1188 if (formData.getBoundary) {1189 request.headers = {1190 'Content-Type': `multipart/form-data; boundary=${formData.getBoundary()}`,1191 };1192 }1193 return this.doFetch<StatusOK>(1194 `${this.getTeamRoute(teamId)}/image`,1195 request,1196 );1197 };1198 removeTeamIcon = (teamId: string) => {1199 this.trackEvent('api', 'api_team_remove_team_icon');1200 return this.doFetch<StatusOK>(1201 `${this.getTeamRoute(teamId)}/image`,1202 {method: 'delete'},1203 );1204 };1205 updateTeamMemberSchemeRoles = (teamId: string, userId: string, isSchemeUser: boolean, isSchemeAdmin: boolean) => {1206 const body = {scheme_user: isSchemeUser, scheme_admin: isSchemeAdmin};1207 return this.doFetch<StatusOK>(1208 `${this.getTeamRoute(teamId)}/members/${userId}/schemeRoles`,1209 {method: 'put', body: JSON.stringify(body)},1210 );1211 };1212 // Channel Routes1213 getAllChannels = (page = 0, perPage = PER_PAGE_DEFAULT, notAssociatedToGroup = '', excludeDefaultChannels = false, includeTotalCount = false, includeDeleted = false, excludePolicyConstrained = false) => {1214 const queryData = {1215 page,1216 per_page: perPage,1217 not_associated_to_group: notAssociatedToGroup,1218 exclude_default_channels: excludeDefaultChannels,1219 include_total_count: includeTotalCount,1220 include_deleted: includeDeleted,1221 exclude_policy_constrained: excludePolicyConstrained,1222 };1223 return this.doFetch<ChannelWithTeamData[] | ChannelsWithTotalCount>(1224 `${this.getChannelsRoute()}${buildQueryString(queryData)}`,1225 {method: 'get'},1226 );1227 };1228 createChannel = (channel: Channel) => {1229 this.trackEvent('api', 'api_channels_create', {team_id: channel.team_id});1230 return this.doFetch<Channel>(1231 `${this.getChannelsRoute()}`,1232 {method: 'post', body: JSON.stringify(channel)},1233 );1234 };1235 createDirectChannel = (userIds: string[]) => {1236 this.trackEvent('api', 'api_channels_create_direct');1237 return this.doFetch<Channel>(1238 `${this.getChannelsRoute()}/direct`,1239 {method: 'post', body: JSON.stringify(userIds)},1240 );1241 };1242 createGroupChannel = (userIds: string[]) => {1243 this.trackEvent('api', 'api_channels_create_group');1244 return this.doFetch<Channel>(1245 `${this.getChannelsRoute()}/group`,1246 {method: 'post', body: JSON.stringify(userIds)},1247 );1248 };1249 deleteChannel = (channelId: string) => {1250 this.trackEvent('api', 'api_channels_delete', {channel_id: channelId});1251 return this.doFetch<StatusOK>(1252 `${this.getChannelRoute(channelId)}`,1253 {method: 'delete'},1254 );1255 };1256 unarchiveChannel = (channelId: string) => {1257 this.trackEvent('api', 'api_channels_unarchive', {channel_id: channelId});1258 return this.doFetch<Channel>(1259 `${this.getChannelRoute(channelId)}/restore`,1260 {method: 'post'},1261 );1262 };1263 updateChannel = (channel: Channel) => {1264 this.trackEvent('api', 'api_channels_update', {channel_id: channel.id});1265 return this.doFetch<Channel>(1266 `${this.getChannelRoute(channel.id)}`,1267 {method: 'put', body: JSON.stringify(channel)},1268 );1269 };1270 convertChannelToPrivate = (channelId: string) => {1271 this.trackEvent('api', 'api_channels_convert_to_private', {channel_id: channelId});1272 return this.doFetch<Channel>(1273 `${this.getChannelRoute(channelId)}/convert`,1274 {method: 'post'},1275 );1276 };1277 updateChannelPrivacy = (channelId: string, privacy: any) => {1278 this.trackEvent('api', 'api_channels_update_privacy', {channel_id: channelId, privacy});1279 return this.doFetch<Channel>(1280 `${this.getChannelRoute(channelId)}/privacy`,1281 {method: 'put', body: JSON.stringify({privacy})},1282 );1283 };1284 patchChannel = (channelId: string, channelPatch: Partial<Channel>) => {1285 this.trackEvent('api', 'api_channels_patch', {channel_id: channelId});1286 return this.doFetch<Channel>(1287 `${this.getChannelRoute(channelId)}/patch`,1288 {method: 'put', body: JSON.stringify(channelPatch)},1289 );1290 };1291 updateChannelNotifyProps = (props: any) => {1292 this.trackEvent('api', 'api_users_update_channel_notifications', {channel_id: props.channel_id});1293 return this.doFetch<StatusOK>(1294 `${this.getChannelMemberRoute(props.channel_id, props.user_id)}/notify_props`,1295 {method: 'put', body: JSON.stringify(props)},1296 );1297 };1298 updateChannelScheme = (channelId: string, schemeId: string) => {1299 const patch = {scheme_id: schemeId};1300 this.trackEvent('api', 'api_channels_update_scheme', {channel_id: channelId, ...patch});1301 return this.doFetch<StatusOK>(1302 `${this.getChannelSchemeRoute(channelId)}`,1303 {method: 'put', body: JSON.stringify(patch)},1304 );1305 };1306 getChannel = (channelId: string) => {1307 this.trackEvent('api', 'api_channel_get', {channel_id: channelId});1308 return this.doFetch<Channel>(1309 `${this.getChannelRoute(channelId)}`,1310 {method: 'get'},1311 );1312 };1313 getChannelByName = (teamId: string, channelName: string, includeDeleted = false) => {1314 return this.doFetch<Channel>(1315 `${this.getTeamRoute(teamId)}/channels/name/${channelName}?include_deleted=${includeDeleted}`,1316 {method: 'get'},1317 );1318 };1319 getChannelByNameAndTeamName = (teamName: string, channelName: string, includeDeleted = false) => {1320 this.trackEvent('api', 'api_channel_get_by_name_and_teamName', {include_deleted: includeDeleted});1321 return this.doFetch<Channel>(1322 `${this.getTeamNameRoute(teamName)}/channels/name/${channelName}?include_deleted=${includeDeleted}`,1323 {method: 'get'},1324 );1325 };1326 getChannels = (teamId: string, page = 0, perPage = PER_PAGE_DEFAULT) => {1327 return this.doFetch<Channel[]>(1328 `${this.getTeamRoute(teamId)}/channels${buildQueryString({page, per_page: perPage})}`,1329 {method: 'get'},1330 );1331 };1332 getArchivedChannels = (teamId: string, page = 0, perPage = PER_PAGE_DEFAULT) => {1333 return this.doFetch<Channel[]>(1334 `${this.getTeamRoute(teamId)}/channels/deleted${buildQueryString({page, per_page: perPage})}`,1335 {method: 'get'},1336 );1337 };1338 getMyChannels = (teamId: string, includeDeleted = false) => {1339 return this.doFetch<Channel[]>(1340 `${this.getUserRoute('me')}/teams/${teamId}/channels${buildQueryString({include_deleted: includeDeleted})}`,1341 {method: 'get'},1342 );1343 };1344 getMyChannelMember = (channelId: string) => {1345 return this.doFetch<ChannelMembership>(1346 `${this.getChannelMemberRoute(channelId, 'me')}`,1347 {method: 'get'},1348 );1349 };1350 getMyChannelMembers = (teamId: string) => {1351 return this.doFetch<ChannelMembership[]>(1352 `${this.getUserRoute('me')}/teams/${teamId}/channels/members`,1353 {method: 'get'},1354 );1355 };1356 getChannelMembers = (channelId: string, page = 0, perPage = PER_PAGE_DEFAULT) => {1357 return this.doFetch<ChannelMembership[]>(1358 `${this.getChannelMembersRoute(channelId)}${buildQueryString({page, per_page: perPage})}`,1359 {method: 'get'},1360 );1361 };1362 getChannelTimezones = (channelId: string) => {1363 return this.doFetch<string[]>(1364 `${this.getChannelRoute(channelId)}/timezones`,1365 {method: 'get'},1366 );1367 };1368 getChannelMember = (channelId: string, userId: string) => {1369 return this.doFetch<ChannelMembership>(1370 `${this.getChannelMemberRoute(channelId, userId)}`,1371 {method: 'get'},1372 );1373 };1374 getChannelMembersByIds = (channelId: string, userIds: string[]) => {1375 return this.doFetch<ChannelMembership[]>(1376 `${this.getChannelMembersRoute(channelId)}/ids`,1377 {method: 'post', body: JSON.stringify(userIds)},1378 );1379 };1380 addToChannel = (userId: string, channelId: string, postRootId = '') => {1381 this.trackEvent('api', 'api_channels_add_member', {channel_id: channelId});1382 const member = {user_id: userId, channel_id: channelId, post_root_id: postRootId};1383 return this.doFetch<ChannelMembership>(1384 `${this.getChannelMembersRoute(channelId)}`,1385 {method: 'post', body: JSON.stringify(member)},1386 );1387 };1388 removeFromChannel = (userId: string, channelId: string) => {1389 this.trackEvent('api', 'api_channels_remove_member', {channel_id: channelId});1390 return this.doFetch<StatusOK>(1391 `${this.getChannelMemberRoute(channelId, userId)}`,1392 {method: 'delete'},1393 );1394 };1395 updateChannelMemberRoles = (channelId: string, userId: string, roles: string) => {1396 return this.doFetch<StatusOK>(1397 `${this.getChannelMemberRoute(channelId, userId)}/roles`,1398 {method: 'put', body: JSON.stringify({roles})},1399 );1400 };1401 getChannelStats = (channelId: string) => {1402 return this.doFetch<ChannelStats>(1403 `${this.getChannelRoute(channelId)}/stats`,1404 {method: 'get'},1405 );1406 };1407 getChannelModerations = (channelId: string) => {1408 return this.doFetch<ChannelModeration[]>(1409 `${this.getChannelRoute(channelId)}/moderations`,1410 {method: 'get'},1411 );1412 };1413 patchChannelModerations = (channelId: string, channelModerationsPatch: ChannelModerationPatch[]) => {1414 return this.doFetch<ChannelModeration[]>(1415 `${this.getChannelRoute(channelId)}/moderations/patch`,1416 {method: 'put', body: JSON.stringify(channelModerationsPatch)},1417 );1418 };1419 getChannelMemberCountsByGroup = (channelId: string, includeTimezones: boolean) => {1420 return this.doFetch<ChannelMemberCountsByGroup>(1421 `${this.getChannelRoute(channelId)}/member_counts_by_group?include_timezones=${includeTimezones}`,1422 {method: 'get'},1423 );1424 };1425 viewMyChannel = (channelId: string, prevChannelId?: string) => {1426 const data = {channel_id: channelId, prev_channel_id: prevChannelId, collapsed_threads_supported: true};1427 return this.doFetch<ChannelViewResponse>(1428 `${this.getChannelsRoute()}/members/me/view`,1429 {method: 'post', body: JSON.stringify(data)},1430 );1431 };1432 autocompleteChannels = (teamId: string, name: string) => {1433 return this.doFetch<Channel[]>(1434 `${this.getTeamRoute(teamId)}/channels/autocomplete${buildQueryString({name})}`,1435 {method: 'get'},1436 );1437 };1438 autocompleteChannelsForSearch = (teamId: string, name: string) => {1439 return this.doFetch<Channel[]>(1440 `${this.getTeamRoute(teamId)}/channels/search_autocomplete${buildQueryString({name})}`,1441 {method: 'get'},1442 );1443 };1444 searchChannels = (teamId: string, term: string) => {1445 return this.doFetch<Channel[]>(1446 `${this.getTeamRoute(teamId)}/channels/search`,1447 {method: 'post', body: JSON.stringify({term})},1448 );1449 };1450 searchArchivedChannels = (teamId: string, term: string) => {1451 return this.doFetch<Channel[]>(1452 `${this.getTeamRoute(teamId)}/channels/search_archived`,1453 {method: 'post', body: JSON.stringify({term})},1454 );1455 };1456 searchAllChannels = (term: string, opts: ChannelSearchOpts = {}) => {1457 const body = {1458 term,1459 ...opts,1460 };1461 const includeDeleted = Boolean(opts.include_deleted);1462 return this.doFetch<Channel[] | ChannelsWithTotalCount>(1463 `${this.getChannelsRoute()}/search?include_deleted=${includeDeleted}`,1464 {method: 'post', body: JSON.stringify(body)},1465 );1466 };1467 searchGroupChannels = (term: string) => {1468 return this.doFetch<Channel[]>(1469 `${this.getChannelsRoute()}/group/search`,1470 {method: 'post', body: JSON.stringify({term})},1471 );1472 };1473 updateChannelMemberSchemeRoles = (channelId: string, userId: string, isSchemeUser: boolean, isSchemeAdmin: boolean) => {1474 const body = {scheme_user: isSchemeUser, scheme_admin: isSchemeAdmin};1475 return this.doFetch<StatusOK>(1476 `${this.getChannelRoute(channelId)}/members/${userId}/schemeRoles`,1477 {method: 'put', body: JSON.stringify(body)},1478 );1479 };1480 // Channel Category Routes1481 getChannelCategories = (userId: string, teamId: string) => {1482 return this.doFetch<OrderedChannelCategories>(1483 `${this.getChannelCategoriesRoute(userId, teamId)}`,1484 {method: 'get'},1485 );1486 };1487 createChannelCategory = (userId: string, teamId: string, category: Partial<ChannelCategory>) => {1488 return this.doFetch<ChannelCategory>(1489 `${this.getChannelCategoriesRoute(userId, teamId)}`,1490 {method: 'post', body: JSON.stringify(category)},1491 );1492 };1493 updateChannelCategories = (userId: string, teamId: string, categories: ChannelCategory[]) => {1494 return this.doFetch<ChannelCategory[]>(1495 `${this.getChannelCategoriesRoute(userId, teamId)}`,1496 {method: 'put', body: JSON.stringify(categories)},1497 );1498 };1499 getChannelCategoryOrder = (userId: string, teamId: string) => {1500 return this.doFetch<string[]>(1501 `${this.getChannelCategoriesRoute(userId, teamId)}/order`,1502 {method: 'get'},1503 );1504 };1505 updateChannelCategoryOrder = (userId: string, teamId: string, categoryOrder: string[]) => {1506 return this.doFetch<string[]>(1507 `${this.getChannelCategoriesRoute(userId, teamId)}/order`,1508 {method: 'put', body: JSON.stringify(categoryOrder)},1509 );1510 };1511 getChannelCategory = (userId: string, teamId: string, categoryId: string) => {1512 return this.doFetch<ChannelCategory>(1513 `${this.getChannelCategoriesRoute(userId, teamId)}/${categoryId}`,1514 {method: 'get'},1515 );1516 };1517 updateChannelCategory = (userId: string, teamId: string, category: ChannelCategory) => {1518 return this.doFetch<ChannelCategory>(1519 `${this.getChannelCategoriesRoute(userId, teamId)}/${category.id}`,1520 {method: 'put', body: JSON.stringify(category)},1521 );1522 };1523 deleteChannelCategory = (userId: string, teamId: string, categoryId: string) => {1524 return this.doFetch<ChannelCategory>(1525 `${this.getChannelCategoriesRoute(userId, teamId)}/${categoryId}`,1526 {method: 'delete'},1527 );1528 }1529 // Post Routes1530 createPost = async (post: Post) => {1531 const result = await this.doFetch<Post>(1532 `${this.getPostsRoute()}`,1533 {method: 'post', body: JSON.stringify(post)},1534 );1535 const analyticsData = {channel_id: result.channel_id, post_id: result.id, user_actual_id: result.user_id, root_id: result.root_id};1536 this.trackEvent('api', 'api_posts_create', analyticsData);1537 if (result.root_id != null && result.root_id !== '') {1538 this.trackEvent('api', 'api_posts_replied', analyticsData);1539 }1540 return result;1541 };1542 updatePost = (post: Post) => {1543 this.trackEvent('api', 'api_posts_update', {channel_id: post.channel_id, post_id: post.id});1544 return this.doFetch<Post>(1545 `${this.getPostRoute(post.id)}`,1546 {method: 'put', body: JSON.stringify(post)},1547 );1548 };1549 getPost = (postId: string) => {1550 return this.doFetch<Post>(1551 `${this.getPostRoute(postId)}`,1552 {method: 'get'},1553 );1554 };1555 patchPost = (postPatch: Partial<Post> & {id: string}) => {1556 this.trackEvent('api', 'api_posts_patch', {channel_id: postPatch.channel_id, post_id: postPatch.id});1557 return this.doFetch<Post>(1558 `${this.getPostRoute(postPatch.id)}/patch`,1559 {method: 'put', body: JSON.stringify(postPatch)},1560 );1561 };1562 deletePost = (postId: string) => {1563 this.trackEvent('api', 'api_posts_delete');1564 return this.doFetch<StatusOK>(1565 `${this.getPostRoute(postId)}`,1566 {method: 'delete'},1567 );1568 };1569 getPostThread = (postId: string, fetchThreads = true, collapsedThreads = false, collapsedThreadsExtended = false) => {1570 return this.doFetch<PostList>(1571 `${this.getPostRoute(postId)}/thread${buildQueryString({skipFetchThreads: !fetchThreads, collapsedThreads, collapsedThreadsExtended})}`,1572 {method: 'get'},1573 );1574 };1575 getPosts = (channelId: string, page = 0, perPage = PER_PAGE_DEFAULT, fetchThreads = true, collapsedThreads = false, collapsedThreadsExtended = false) => {1576 return this.doFetch<PostList>(1577 `${this.getChannelRoute(channelId)}/posts${buildQueryString({page, per_page: perPage, skipFetchThreads: !fetchThreads, collapsedThreads, collapsedThreadsExtended})}`,1578 {method: 'get'},1579 );1580 };1581 getPostsUnread = (channelId: string, userId: string, limitAfter = DEFAULT_LIMIT_AFTER, limitBefore = DEFAULT_LIMIT_BEFORE, fetchThreads = true, collapsedThreads = false, collapsedThreadsExtended = false) => {1582 return this.doFetch<PostList>(1583 `${this.getUserRoute(userId)}/channels/${channelId}/posts/unread${buildQueryString({limit_after: limitAfter, limit_before: limitBefore, skipFetchThreads: !fetchThreads, collapsedThreads, collapsedThreadsExtended})}`,1584 {method: 'get'},1585 );1586 };1587 getPostsSince = (channelId: string, since: number, fetchThreads = true, collapsedThreads = false, collapsedThreadsExtended = false) => {1588 return this.doFetch<PostList>(1589 `${this.getChannelRoute(channelId)}/posts${buildQueryString({since, skipFetchThreads: !fetchThreads, collapsedThreads, collapsedThreadsExtended})}`,1590 {method: 'get'},1591 );1592 };1593 getPostsBefore = (channelId: string, postId: string, page = 0, perPage = PER_PAGE_DEFAULT, fetchThreads = true, collapsedThreads = false, collapsedThreadsExtended = false) => {1594 this.trackEvent('api', 'api_posts_get_before', {channel_id: channelId});1595 return this.doFetch<PostList>(1596 `${this.getChannelRoute(channelId)}/posts${buildQueryString({before: postId, page, per_page: perPage, skipFetchThreads: !fetchThreads, collapsedThreads, collapsedThreadsExtended})}`,1597 {method: 'get'},1598 );1599 };1600 getPostsAfter = (channelId: string, postId: string, page = 0, perPage = PER_PAGE_DEFAULT, fetchThreads = true, collapsedThreads = false, collapsedThreadsExtended = false) => {1601 this.trackEvent('api', 'api_posts_get_after', {channel_id: channelId});1602 return this.doFetch<PostList>(1603 `${this.getChannelRoute(channelId)}/posts${buildQueryString({after: postId, page, per_page: perPage, skipFetchThreads: !fetchThreads, collapsedThreads, collapsedThreadsExtended})}`,1604 {method: 'get'},1605 );1606 };1607 getUserThreads = (1608 userId: $ID<UserProfile> = 'me',1609 teamId: $ID<Team>,1610 {1611 before = '',1612 after = '',1613 pageSize = PER_PAGE_DEFAULT,1614 extended = false,1615 deleted = false,1616 unread = false,1617 since = 0,1618 },1619 ) => {1620 return this.doFetch<UserThreadList>(1621 `${this.getUserThreadsRoute(userId, teamId)}${buildQueryString({before, after, pageSize, extended, deleted, unread, since})}`,1622 {method: 'get'},1623 );1624 };1625 getUserThread = (userId: string, teamId: string, threadId: string, extended = false) => {1626 const url = `${this.getUserThreadRoute(userId, teamId, threadId)}`;1627 return this.doFetch<UserThreadWithPost>(1628 `${url}${buildQueryString({extended})}`,1629 {method: 'get'},1630 );1631 };1632 updateThreadsReadForUser = (userId: string, teamId: string) => {1633 const url = `${this.getUserThreadsRoute(userId, teamId)}/read`;1634 return this.doFetch<StatusOK>(1635 url,1636 {method: 'put'},1637 );1638 };1639 updateThreadReadForUser = (userId: string, teamId: string, threadId: string, timestamp: number) => {1640 const url = `${this.getUserThreadRoute(userId, teamId, threadId)}/read/${timestamp}`;1641 return this.doFetch<UserThread>(1642 url,1643 {method: 'put'},1644 );1645 };1646 updateThreadFollowForUser = (userId: string, teamId: string, threadId: string, state: boolean) => {1647 const url = this.getUserThreadRoute(userId, teamId, threadId) + '/following';1648 return this.doFetch<StatusOK>(1649 url,1650 {method: state ? 'put' : 'delete'},1651 );1652 };1653 getFileInfosForPost = (postId: string) => {1654 return this.doFetch<FileInfo[]>(1655 `${this.getPostRoute(postId)}/files/info`,1656 {method: 'get'},1657 );1658 };1659 getFlaggedPosts = (userId: string, channelId = '', teamId = '', page = 0, perPage = PER_PAGE_DEFAULT) => {1660 this.trackEvent('api', 'api_posts_get_flagged', {team_id: teamId});1661 return this.doFetch<PostList>(1662 `${this.getUserRoute(userId)}/posts/flagged${buildQueryString({channel_id: channelId, team_id: teamId, page, per_page: perPage})}`,1663 {method: 'get'},1664 );1665 };1666 getPinnedPosts = (channelId: string) => {1667 this.trackEvent('api', 'api_posts_get_pinned', {channel_id: channelId});1668 return this.doFetch<PostList>(1669 `${this.getChannelRoute(channelId)}/pinned`,1670 {method: 'get'},1671 );1672 };1673 markPostAsUnread = (userId: string, postId: string) => {1674 this.trackEvent('api', 'api_post_set_unread_post');1675 return this.doFetch<ChannelUnread>(1676 `${this.getUserRoute(userId)}/posts/${postId}/set_unread`,1677 {method: 'post', body: JSON.stringify({collapsed_threads_supported: true})},1678 );1679 }1680 pinPost = (postId: string) => {1681 this.trackEvent('api', 'api_posts_pin');1682 return this.doFetch<StatusOK>(1683 `${this.getPostRoute(postId)}/pin`,1684 {method: 'post'},1685 );1686 };1687 unpinPost = (postId: string) => {1688 this.trackEvent('api', 'api_posts_unpin');1689 return this.doFetch<StatusOK>(1690 `${this.getPostRoute(postId)}/unpin`,1691 {method: 'post'},1692 );1693 };1694 addReaction = (userId: string, postId: string, emojiName: string) => {1695 this.trackEvent('api', 'api_reactions_save', {post_id: postId});1696 return this.doFetch<Reaction>(1697 `${this.getReactionsRoute()}`,1698 {method: 'post', body: JSON.stringify({user_id: userId, post_id: postId, emoji_name: emojiName})},1699 );1700 };1701 removeReaction = (userId: string, postId: string, emojiName: string) => {1702 this.trackEvent('api', 'api_reactions_delete', {post_id: postId});1703 return this.doFetch<StatusOK>(1704 `${this.getUserRoute(userId)}/posts/${postId}/reactions/${emojiName}`,1705 {method: 'delete'},1706 );1707 };1708 getReactionsForPost = (postId: string) => {1709 return this.doFetch<Reaction[]>(1710 `${this.getPostRoute(postId)}/reactions`,1711 {method: 'get'},1712 );1713 };1714 searchPostsWithParams = (teamId: string, params: any) => {1715 this.trackEvent('api', 'api_posts_search', {team_id: teamId});1716 return this.doFetch<PostSearchResults>(1717 `${this.getTeamRoute(teamId)}/posts/search`,1718 {method: 'post', body: JSON.stringify(params)},1719 );1720 };1721 searchPosts = (teamId: string, terms: string, isOrSearch: boolean) => {1722 return this.searchPostsWithParams(teamId, {terms, is_or_search: isOrSearch});1723 };1724 searchFilesWithParams = (teamId: string, params: any) => {1725 this.trackEvent('api', 'api_files_search', {team_id: teamId});1726 return this.doFetch<FileSearchResults>(1727 `${this.getTeamRoute(teamId)}/files/search`,1728 {method: 'post', body: JSON.stringify(params)},1729 );1730 };1731 searchFiles = (teamId: string, terms: string, isOrSearch: boolean) => {1732 return this.searchFilesWithParams(teamId, {terms, is_or_search: isOrSearch});1733 };1734 getOpenGraphMetadata = (url: string) => {1735 return this.doFetch<OpenGraphMetadata>(1736 `${this.getBaseRoute()}/opengraph`,1737 {method: 'post', body: JSON.stringify({url})},1738 );1739 };1740 doPostAction = (postId: string, actionId: string, selectedOption = '') => {1741 return this.doPostActionWithCookie(postId, actionId, '', selectedOption);1742 };1743 doPostActionWithCookie = (postId: string, actionId: string, actionCookie: string, selectedOption = '') => {1744 if (selectedOption) {1745 this.trackEvent('api', 'api_interactive_messages_menu_selected');1746 } else {1747 this.trackEvent('api', 'api_interactive_messages_button_clicked');1748 }1749 const msg: any = {1750 selected_option: selectedOption,1751 };1752 if (actionCookie !== '') {1753 msg.cookie = actionCookie;1754 }1755 return this.doFetch<PostActionResponse>(1756 `${this.getPostRoute(postId)}/actions/${encodeURIComponent(actionId)}`,1757 {method: 'post', body: JSON.stringify(msg)},1758 );1759 };1760 // Files Routes1761 getFileUrl(fileId: string, timestamp: number) {1762 let url = `${this.getFileRoute(fileId)}`;1763 if (timestamp) {1764 url += `?${timestamp}`;1765 }1766 return url;1767 }1768 getFileThumbnailUrl(fileId: string, timestamp: number) {1769 let url = `${this.getFileRoute(fileId)}/thumbnail`;1770 if (timestamp) {1771 url += `?${timestamp}`;1772 }1773 return url;1774 }1775 getFilePreviewUrl(fileId: string, timestamp: number) {1776 let url = `${this.getFileRoute(fileId)}/preview`;1777 if (timestamp) {1778 url += `?${timestamp}`;1779 }1780 return url;1781 }1782 uploadFile = (fileFormData: any, formBoundary: string) => {1783 this.trackEvent('api', 'api_files_upload');1784 const request: any = {1785 method: 'post',1786 body: fileFormData,1787 };1788 if (formBoundary) {1789 request.headers = {1790 'Content-Type': `multipart/form-data; boundary=${formBoundary}`,1791 };1792 }1793 return this.doFetch<FileUploadResponse>(1794 `${this.getFilesRoute()}`,1795 request,1796 );1797 };1798 getFilePublicLink = (fileId: string) => {1799 return this.doFetch<{1800 link: string;1801 }>(1802 `${this.getFileRoute(fileId)}/link`,1803 {method: 'get'},1804 );1805 }1806 // Preference Routes1807 savePreferences = (userId: string, preferences: PreferenceType[]) => {1808 return this.doFetch<StatusOK>(1809 `${this.getPreferencesRoute(userId)}`,1810 {method: 'put', body: JSON.stringify(preferences)},1811 );1812 };1813 getMyPreferences = () => {1814 return this.doFetch<PreferenceType>(1815 `${this.getPreferencesRoute('me')}`,1816 {method: 'get'},1817 );1818 };1819 deletePreferences = (userId: string, preferences: PreferenceType[]) => {1820 return this.doFetch<StatusOK>(1821 `${this.getPreferencesRoute(userId)}/delete`,1822 {method: 'post', body: JSON.stringify(preferences)},1823 );1824 };1825 // General Routes1826 ping = () => {1827 return this.doFetch<{1828 status: string;1829 }>(1830 `${this.getBaseRoute()}/system/ping?time=${Date.now()}`,1831 {method: 'get'},1832 );1833 };1834 upgradeToEnterprise = async () => {1835 return this.doFetch<StatusOK>(1836 `${this.getBaseRoute()}/upgrade_to_enterprise`,1837 {method: 'post'},1838 );1839 }1840 upgradeToEnterpriseStatus = async () => {1841 return this.doFetch<{1842 percentage: number;1843 error: string | null;1844 }>(1845 `${this.getBaseRoute()}/upgrade_to_enterprise/status`,1846 {method: 'get'},1847 );1848 }1849 restartServer = async () => {1850 return this.doFetch<StatusOK>(1851 `${this.getBaseRoute()}/restart`,1852 {method: 'post'},1853 );1854 }1855 logClientError = (message: string, level = 'ERROR') => {1856 const url = `${this.getBaseRoute()}/logs`;1857 if (!this.enableLogging) {1858 throw new ClientError(this.getUrl(), {1859 message: 'Logging disabled.',1860 url,1861 });1862 }1863 return this.doFetch<{1864 message: string;1865 }>(1866 url,1867 {method: 'post', body: JSON.stringify({message, level})},1868 );1869 };1870 getClientConfigOld = () => {1871 return this.doFetch<ClientConfig>(1872 `${this.getBaseRoute()}/config/client?format=old`,1873 {method: 'get'},1874 );1875 };1876 getClientLicenseOld = () => {1877 return this.doFetch<ClientLicense>(1878 `${this.getBaseRoute()}/license/client?format=old`,1879 {method: 'get'},1880 );1881 };1882 getWarnMetricsStatus = async () => {1883 return this.doFetch(1884 `${this.getBaseRoute()}/warn_metrics/status`,1885 {method: 'get'},1886 );1887 };1888 sendWarnMetricAck = async (warnMetricId: string, forceAckVal: boolean) => {1889 return this.doFetch(1890 `${this.getBaseRoute()}/warn_metrics/ack/${encodeURI(warnMetricId)}`,1891 {method: 'post', body: JSON.stringify({forceAck: forceAckVal})},1892 );1893 }1894 setFirstAdminVisitMarketplaceStatus = async () => {1895 return this.doFetch<StatusOK>(1896 `${this.getPluginsRoute()}/marketplace/first_admin_visit`,1897 {method: 'post', body: JSON.stringify({first_admin_visit_marketplace_status: true})},1898 );1899 }1900 getFirstAdminVisitMarketplaceStatus = async () => {1901 return this.doFetch<SystemSetting>(1902 `${this.getPluginsRoute()}/marketplace/first_admin_visit`,1903 {method: 'get'},1904 );1905 };1906 getTranslations = (url: string) => {1907 return this.doFetch<Record<string, string>>(1908 url,1909 {method: 'get'},1910 );1911 };1912 getWebSocketUrl = () => {1913 return `${this.getBaseRoute()}/websocket`;1914 }1915 // Integration Routes1916 createIncomingWebhook = (hook: IncomingWebhook) => {1917 this.trackEvent('api', 'api_integrations_created', {team_id: hook.team_id});1918 return this.doFetch<IncomingWebhook>(1919 `${this.getIncomingHooksRoute()}`,1920 {method: 'post', body: JSON.stringify(hook)},1921 );1922 };1923 getIncomingWebhook = (hookId: string) => {1924 return this.doFetch<IncomingWebhook>(1925 `${this.getIncomingHookRoute(hookId)}`,1926 {method: 'get'},1927 );1928 };1929 getIncomingWebhooks = (teamId = '', page = 0, perPage = PER_PAGE_DEFAULT) => {1930 const queryParams: any = {1931 page,1932 per_page: perPage,1933 };1934 if (teamId) {1935 queryParams.team_id = teamId;1936 }1937 return this.doFetch<IncomingWebhook[]>(1938 `${this.getIncomingHooksRoute()}${buildQueryString(queryParams)}`,1939 {method: 'get'},1940 );1941 };1942 removeIncomingWebhook = (hookId: string) => {1943 this.trackEvent('api', 'api_integrations_deleted');1944 return this.doFetch<StatusOK>(1945 `${this.getIncomingHookRoute(hookId)}`,1946 {method: 'delete'},1947 );1948 };1949 updateIncomingWebhook = (hook: IncomingWebhook) => {1950 this.trackEvent('api', 'api_integrations_updated', {team_id: hook.team_id});1951 return this.doFetch<IncomingWebhook>(1952 `${this.getIncomingHookRoute(hook.id)}`,1953 {method: 'put', body: JSON.stringify(hook)},1954 );1955 };1956 createOutgoingWebhook = (hook: OutgoingWebhook) => {1957 this.trackEvent('api', 'api_integrations_created', {team_id: hook.team_id});1958 return this.doFetch<OutgoingWebhook>(1959 `${this.getOutgoingHooksRoute()}`,1960 {method: 'post', body: JSON.stringify(hook)},1961 );1962 };1963 getOutgoingWebhook = (hookId: string) => {1964 return this.doFetch<OutgoingWebhook>(1965 `${this.getOutgoingHookRoute(hookId)}`,1966 {method: 'get'},1967 );1968 };1969 getOutgoingWebhooks = (channelId = '', teamId = '', page = 0, perPage = PER_PAGE_DEFAULT) => {1970 const queryParams: any = {1971 page,1972 per_page: perPage,1973 };1974 if (channelId) {1975 queryParams.channel_id = channelId;1976 }1977 if (teamId) {1978 queryParams.team_id = teamId;1979 }1980 return this.doFetch<OutgoingWebhook[]>(1981 `${this.getOutgoingHooksRoute()}${buildQueryString(queryParams)}`,1982 {method: 'get'},1983 );1984 };1985 removeOutgoingWebhook = (hookId: string) => {1986 this.trackEvent('api', 'api_integrations_deleted');1987 return this.doFetch<StatusOK>(1988 `${this.getOutgoingHookRoute(hookId)}`,1989 {method: 'delete'},1990 );1991 };1992 updateOutgoingWebhook = (hook: OutgoingWebhook) => {1993 this.trackEvent('api', 'api_integrations_updated', {team_id: hook.team_id});1994 return this.doFetch<OutgoingWebhook>(1995 `${this.getOutgoingHookRoute(hook.id)}`,1996 {method: 'put', body: JSON.stringify(hook)},1997 );1998 };1999 regenOutgoingHookToken = (id: string) => {2000 return this.doFetch<OutgoingWebhook>(2001 `${this.getOutgoingHookRoute(id)}/regen_token`,2002 {method: 'post'},2003 );2004 };2005 getCommandsList = (teamId: string) => {2006 return this.doFetch<Command[]>(2007 `${this.getCommandsRoute()}?team_id=${teamId}`,2008 {method: 'get'},2009 );2010 };2011 getCommandAutocompleteSuggestionsList = (userInput: string, teamId: string, commandArgs: CommandArgs) => {2012 return this.doFetch<AutocompleteSuggestion[]>(2013 `${this.getTeamRoute(teamId)}/commands/autocomplete_suggestions${buildQueryString({...commandArgs, user_input: userInput})}`,2014 {method: 'get'},2015 );2016 };2017 getAutocompleteCommandsList = (teamId: string, page = 0, perPage = PER_PAGE_DEFAULT) => {2018 return this.doFetch<Command[]>(2019 `${this.getTeamRoute(teamId)}/commands/autocomplete${buildQueryString({page, per_page: perPage})}`,2020 {method: 'get'},2021 );2022 };2023 getCustomTeamCommands = (teamId: string) => {2024 return this.doFetch<Command[]>(2025 `${this.getCommandsRoute()}?team_id=${teamId}&custom_only=true`,2026 {method: 'get'},2027 );2028 };2029 executeCommand = (command: string, commandArgs: CommandArgs) => {2030 this.trackEvent('api', 'api_integrations_used');2031 return this.doFetch<CommandResponse>(2032 `${this.getCommandsRoute()}/execute`,2033 {method: 'post', body: JSON.stringify({command, ...commandArgs})},2034 );2035 };2036 addCommand = (command: Command) => {2037 this.trackEvent('api', 'api_integrations_created');2038 return this.doFetch<Command>(2039 `${this.getCommandsRoute()}`,2040 {method: 'post', body: JSON.stringify(command)},2041 );2042 };2043 editCommand = (command: Command) => {2044 this.trackEvent('api', 'api_integrations_created');2045 return this.doFetch<Command>(2046 `${this.getCommandsRoute()}/${command.id}`,2047 {method: 'put', body: JSON.stringify(command)},2048 );2049 };2050 regenCommandToken = (id: string) => {2051 return this.doFetch<{2052 token: string;2053 }>(2054 `${this.getCommandsRoute()}/${id}/regen_token`,2055 {method: 'put'},2056 );2057 };2058 deleteCommand = (id: string) => {2059 this.trackEvent('api', 'api_integrations_deleted');2060 return this.doFetch<StatusOK>(2061 `${this.getCommandsRoute()}/${id}`,2062 {method: 'delete'},2063 );2064 };2065 createOAuthApp = (app: OAuthApp) => {2066 this.trackEvent('api', 'api_apps_register');2067 return this.doFetch<OAuthApp>(2068 `${this.getOAuthAppsRoute()}`,2069 {method: 'post', body: JSON.stringify(app)},2070 );2071 };2072 editOAuthApp = (app: OAuthApp) => {2073 return this.doFetch<OAuthApp>(2074 `${this.getOAuthAppsRoute()}/${app.id}`,2075 {method: 'put', body: JSON.stringify(app)},2076 );2077 };2078 getOAuthApps = (page = 0, perPage = PER_PAGE_DEFAULT) => {2079 return this.doFetch<OAuthApp[]>(2080 `${this.getOAuthAppsRoute()}${buildQueryString({page, per_page: perPage})}`,2081 {method: 'get'},2082 );2083 };2084 getAppsOAuthAppIDs = () => {2085 return this.doFetch<string[]>(2086 `${this.getAppsProxyRoute()}/api/v1/oauth-app-ids`,2087 {method: 'get'},2088 );2089 }2090 getAppsBotIDs = () => {2091 return this.doFetch<string[]>(2092 `${this.getAppsProxyRoute()}/api/v1/bot-ids`,2093 {method: 'get'},2094 );2095 }2096 getOAuthApp = (appId: string) => {2097 return this.doFetch<OAuthApp>(2098 `${this.getOAuthAppRoute(appId)}`,2099 {method: 'get'},2100 );2101 };2102 getOAuthAppInfo = (appId: string) => {2103 return this.doFetch<OAuthApp>(2104 `${this.getOAuthAppRoute(appId)}/info`,2105 {method: 'get'},2106 );2107 };2108 deleteOAuthApp = (appId: string) => {2109 this.trackEvent('api', 'api_apps_delete');2110 return this.doFetch<StatusOK>(2111 `${this.getOAuthAppRoute(appId)}`,2112 {method: 'delete'},2113 );2114 };2115 regenOAuthAppSecret = (appId: string) => {2116 return this.doFetch<OAuthApp>(2117 `${this.getOAuthAppRoute(appId)}/regen_secret`,2118 {method: 'post'},2119 );2120 };2121 submitInteractiveDialog = (data: DialogSubmission) => {2122 this.trackEvent('api', 'api_interactive_messages_dialog_submitted');2123 return this.doFetch<SubmitDialogResponse>(2124 `${this.getBaseRoute()}/actions/dialogs/submit`,2125 {method: 'post', body: JSON.stringify(data)},2126 );2127 };2128 // Emoji Routes2129 createCustomEmoji = (emoji: CustomEmoji, imageData: File) => {2130 this.trackEvent('api', 'api_emoji_custom_add');2131 const formData = new FormData();2132 formData.append('image', imageData);2133 formData.append('emoji', JSON.stringify(emoji));2134 const request: any = {2135 method: 'post',2136 body: formData,2137 };2138 if (formData.getBoundary) {2139 request.headers = {2140 'Content-Type': `multipart/form-data; boundary=${formData.getBoundary()}`,2141 };2142 }2143 return this.doFetch<CustomEmoji>(2144 `${this.getEmojisRoute()}`,2145 request,2146 );2147 };2148 getCustomEmoji = (id: string) => {2149 return this.doFetch<CustomEmoji>(2150 `${this.getEmojisRoute()}/${id}`,2151 {method: 'get'},2152 );2153 };2154 getCustomEmojiByName = (name: string) => {2155 return this.doFetch<CustomEmoji>(2156 `${this.getEmojisRoute()}/name/${name}`,2157 {method: 'get'},2158 );2159 };2160 getCustomEmojis = (page = 0, perPage = PER_PAGE_DEFAULT, sort = '') => {2161 return this.doFetch<CustomEmoji[]>(2162 `${this.getEmojisRoute()}${buildQueryString({page, per_page: perPage, sort})}`,2163 {method: 'get'},2164 );2165 };2166 deleteCustomEmoji = (emojiId: string) => {2167 this.trackEvent('api', 'api_emoji_custom_delete');2168 return this.doFetch<StatusOK>(2169 `${this.getEmojiRoute(emojiId)}`,2170 {method: 'delete'},2171 );2172 };2173 getSystemEmojiImageUrl = (filename: string) => {2174 return `${this.url}/static/emoji/${filename}.png`;2175 };2176 getCustomEmojiImageUrl = (id: string) => {2177 return `${this.getEmojiRoute(id)}/image`;2178 };2179 searchCustomEmoji = (term: string, options = {}) => {2180 return this.doFetch<CustomEmoji[]>(2181 `${this.getEmojisRoute()}/search`,2182 {method: 'post', body: JSON.stringify({term, ...options})},2183 );2184 };2185 autocompleteCustomEmoji = (name: string) => {2186 return this.doFetch<CustomEmoji[]>(2187 `${this.getEmojisRoute()}/autocomplete${buildQueryString({name})}`,2188 {method: 'get'},2189 );2190 };2191 // Timezone Routes2192 getTimezones = () => {2193 return this.doFetch<string[]>(2194 `${this.getTimezonesRoute()}`,2195 {method: 'get'},2196 );2197 };2198 // Data Retention2199 getDataRetentionPolicy = () => {2200 return this.doFetch<DataRetentionPolicy>(2201 `${this.getDataRetentionRoute()}/policy`,2202 {method: 'get'},2203 );2204 };2205 getDataRetentionCustomPolicies = (page = 0, perPage = PER_PAGE_DEFAULT) => {2206 return this.doFetch<GetDataRetentionCustomPoliciesRequest>(2207 `${this.getDataRetentionRoute()}/policies${buildQueryString({page, per_page: perPage})}`,2208 {method: 'get'},2209 );2210 };2211 getDataRetentionCustomPolicy = (id: string) => {2212 return this.doFetch<DataRetentionCustomPolicies>(2213 `${this.getDataRetentionRoute()}/policies/${id}`,2214 {method: 'get'},2215 );2216 };2217 deleteDataRetentionCustomPolicy = (id: string) => {2218 return this.doFetch<DataRetentionCustomPolicies>(2219 `${this.getDataRetentionRoute()}/policies/${id}`,2220 {method: 'delete'},2221 );2222 };2223 searchDataRetentionCustomPolicyChannels = (policyId: string, term: string, opts: ChannelSearchOpts) => {2224 return this.doFetch<DataRetentionCustomPolicies>(2225 `${this.getDataRetentionRoute()}/policies/${policyId}/channels/search`,2226 {method: 'post', body: JSON.stringify({term, ...opts})},2227 );2228 }2229 searchDataRetentionCustomPolicyTeams = (policyId: string, term: string, opts: TeamSearchOpts) => {2230 return this.doFetch<DataRetentionCustomPolicies>(2231 `${this.getDataRetentionRoute()}/policies/${policyId}/teams/search`,2232 {method: 'post', body: JSON.stringify({term, ...opts})},2233 );2234 }2235 getDataRetentionCustomPolicyTeams = (id: string, page = 0, perPage = PER_PAGE_DEFAULT, includeTotalCount = false) => {2236 return this.doFetch<Team[]>(2237 `${this.getDataRetentionRoute()}/policies/${id}/teams${buildQueryString({page, per_page: perPage, include_total_count: includeTotalCount})}`,2238 {method: 'get'},2239 );2240 };2241 getDataRetentionCustomPolicyChannels = (id: string, page = 0, perPage = PER_PAGE_DEFAULT) => {2242 return this.doFetch<{channels: Channel[]; total_count: number}>(2243 `${this.getDataRetentionRoute()}/policies/${id}/channels${buildQueryString({page, per_page: perPage})}`,2244 {method: 'get'},2245 );2246 };2247 createDataRetentionPolicy = (policy: CreateDataRetentionCustomPolicy) => {2248 return this.doFetch<DataRetentionCustomPolicies>(2249 `${this.getDataRetentionRoute()}/policies`,2250 {method: 'post', body: JSON.stringify(policy)},2251 );2252 };2253 updateDataRetentionPolicy = (id: string, policy: PatchDataRetentionCustomPolicy) => {2254 return this.doFetch<DataRetentionCustomPolicies>(2255 `${this.getDataRetentionRoute()}/policies/${id}`,2256 {method: 'PATCH', body: JSON.stringify(policy)},2257 );2258 };2259 addDataRetentionPolicyTeams = (id: string, teams: string[]) => {2260 return this.doFetch<DataRetentionCustomPolicies>(2261 `${this.getDataRetentionRoute()}/policies/${id}/teams`,2262 {method: 'post', body: JSON.stringify(teams)},2263 );2264 };2265 removeDataRetentionPolicyTeams = (id: string, teams: string[]) => {2266 return this.doFetch<DataRetentionCustomPolicies>(2267 `${this.getDataRetentionRoute()}/policies/${id}/teams`,2268 {method: 'delete', body: JSON.stringify(teams)},2269 );2270 };2271 addDataRetentionPolicyChannels = (id: string, channels: string[]) => {2272 return this.doFetch<DataRetentionCustomPolicies>(2273 `${this.getDataRetentionRoute()}/policies/${id}/channels`,2274 {method: 'post', body: JSON.stringify(channels)},2275 );2276 };2277 removeDataRetentionPolicyChannels = (id: string, channels: string[]) => {2278 return this.doFetch<DataRetentionCustomPolicies>(2279 `${this.getDataRetentionRoute()}/policies/${id}/channels`,2280 {method: 'delete', body: JSON.stringify(channels)},2281 );2282 };2283 // Jobs Routes2284 getJob = (id: string) => {2285 return this.doFetch<Job>(2286 `${this.getJobsRoute()}/${id}`,2287 {method: 'get'},2288 );2289 };2290 getJobs = (page = 0, perPage = PER_PAGE_DEFAULT) => {2291 return this.doFetch<Job[]>(2292 `${this.getJobsRoute()}${buildQueryString({page, per_page: perPage})}`,2293 {method: 'get'},2294 );2295 };2296 getJobsByType = (type: string, page = 0, perPage = PER_PAGE_DEFAULT) => {2297 return this.doFetch<Job[]>(2298 `${this.getJobsRoute()}/type/${type}${buildQueryString({page, per_page: perPage})}`,2299 {method: 'get'},2300 );2301 };2302 createJob = (job: Job) => {2303 return this.doFetch<Job>(2304 `${this.getJobsRoute()}`,2305 {method: 'post', body: JSON.stringify(job)},2306 );2307 };2308 cancelJob = (id: string) => {2309 return this.doFetch<StatusOK>(2310 `${this.getJobsRoute()}/${id}/cancel`,2311 {method: 'post'},2312 );2313 };2314 // Admin Routes2315 getLogs = (page = 0, perPage = LOGS_PER_PAGE_DEFAULT) => {2316 return this.doFetch<string[]>(2317 `${this.getBaseRoute()}/logs${buildQueryString({page, logs_per_page: perPage})}`,2318 {method: 'get'},2319 );2320 };2321 getAudits = (page = 0, perPage = PER_PAGE_DEFAULT) => {2322 return this.doFetch<Audit[]>(2323 `${this.getBaseRoute()}/audits${buildQueryString({page, per_page: perPage})}`,2324 {method: 'get'},2325 );2326 };2327 getConfig = () => {2328 return this.doFetch<AdminConfig>(2329 `${this.getBaseRoute()}/config`,2330 {method: 'get'},2331 );2332 };2333 updateConfig = (config: AdminConfig) => {2334 return this.doFetch<AdminConfig>(2335 `${this.getBaseRoute()}/config`,2336 {method: 'put', body: JSON.stringify(config)},2337 );2338 };2339 reloadConfig = () => {2340 return this.doFetch<StatusOK>(2341 `${this.getBaseRoute()}/config/reload`,2342 {method: 'post'},2343 );2344 };2345 getEnvironmentConfig = () => {2346 return this.doFetch<EnvironmentConfig>(2347 `${this.getBaseRoute()}/config/environment`,2348 {method: 'get'},2349 );2350 };2351 testEmail = (config: AdminConfig) => {2352 return this.doFetch<StatusOK>(2353 `${this.getBaseRoute()}/email/test`,2354 {method: 'post', body: JSON.stringify(config)},2355 );2356 };2357 testSiteURL = (siteURL: string) => {2358 return this.doFetch<StatusOK>(2359 `${this.getBaseRoute()}/site_url/test`,2360 {method: 'post', body: JSON.stringify({site_url: siteURL})},2361 );2362 };2363 testS3Connection = (config: ClientConfig) => {2364 return this.doFetch<StatusOK>(2365 `${this.getBaseRoute()}/file/s3_test`,2366 {method: 'post', body: JSON.stringify(config)},2367 );2368 };2369 invalidateCaches = () => {2370 return this.doFetch<StatusOK>(2371 `${this.getBaseRoute()}/caches/invalidate`,2372 {method: 'post'},2373 );2374 };2375 recycleDatabase = () => {2376 return this.doFetch<StatusOK>(2377 `${this.getBaseRoute()}/database/recycle`,2378 {method: 'post'},2379 );2380 };2381 createComplianceReport = (job: Partial<Compliance>) => {2382 return this.doFetch<Compliance>(2383 `${this.getBaseRoute()}/compliance/reports`,2384 {method: 'post', body: JSON.stringify(job)},2385 );2386 };2387 getComplianceReport = (reportId: string) => {2388 return this.doFetch<Compliance>(2389 `${this.getBaseRoute()}/compliance/reports/${reportId}`,2390 {method: 'get'},2391 );2392 };2393 getComplianceReports = (page = 0, perPage = PER_PAGE_DEFAULT) => {2394 return this.doFetch<Compliance[]>(2395 `${this.getBaseRoute()}/compliance/reports${buildQueryString({page, per_page: perPage})}`,2396 {method: 'get'},2397 );2398 };2399 uploadBrandImage = (imageData: File) => {2400 const formData = new FormData();2401 formData.append('image', imageData);2402 const request: any = {2403 method: 'post',2404 body: formData,2405 };2406 if (formData.getBoundary) {2407 request.headers = {2408 'Content-Type': `multipart/form-data; boundary=${formData.getBoundary()}`,2409 };2410 }2411 return this.doFetch<StatusOK>(2412 `${this.getBrandRoute()}/image`,2413 request,2414 );2415 };2416 deleteBrandImage = () => {2417 return this.doFetch<StatusOK>(2418 `${this.getBrandRoute()}/image`,2419 {method: 'delete'},2420 );2421 };2422 getClusterStatus = () => {2423 return this.doFetch<ClusterInfo[]>(2424 `${this.getBaseRoute()}/cluster/status`,2425 {method: 'get'},2426 );2427 };2428 testLdap = () => {2429 return this.doFetch<StatusOK>(2430 `${this.getBaseRoute()}/ldap/test`,2431 {method: 'post'},2432 );2433 };2434 syncLdap = () => {2435 return this.doFetch<StatusOK>(2436 `${this.getBaseRoute()}/ldap/sync`,2437 {method: 'post'},2438 );2439 };2440 getLdapGroups = (page = 0, perPage = PER_PAGE_DEFAULT, opts = {}) => {2441 const query = {page, per_page: perPage, ...opts};2442 return this.doFetch<{2443 count: number;2444 groups: MixedUnlinkedGroup[];2445 }>(2446 `${this.getBaseRoute()}/ldap/groups${buildQueryString(query)}`,2447 {method: 'get'},2448 );2449 };2450 linkLdapGroup = (key: string) => {2451 return this.doFetch<Group>(2452 `${this.getBaseRoute()}/ldap/groups/${encodeURI(key)}/link`,2453 {method: 'post'},2454 );2455 };2456 unlinkLdapGroup = (key: string) => {2457 return this.doFetch<StatusOK>(2458 `${this.getBaseRoute()}/ldap/groups/${encodeURI(key)}/link`,2459 {method: 'delete'},2460 );2461 };2462 getSamlCertificateStatus = () => {2463 return this.doFetch<SamlCertificateStatus>(2464 `${this.getBaseRoute()}/saml/certificate/status`,2465 {method: 'get'},2466 );2467 };2468 uploadPublicSamlCertificate = (fileData: File) => {2469 const formData = new FormData();2470 formData.append('certificate', fileData);2471 return this.doFetch<StatusOK>(2472 `${this.getBaseRoute()}/saml/certificate/public`,2473 {2474 method: 'post',2475 body: formData,2476 },2477 );2478 };2479 uploadPrivateSamlCertificate = (fileData: File) => {2480 const formData = new FormData();2481 formData.append('certificate', fileData);2482 return this.doFetch<StatusOK>(2483 `${this.getBaseRoute()}/saml/certificate/private`,2484 {2485 method: 'post',2486 body: formData,2487 },2488 );2489 };2490 uploadPublicLdapCertificate = (fileData: File) => {2491 const formData = new FormData();2492 formData.append('certificate', fileData);2493 return this.doFetch<StatusOK>(2494 `${this.getBaseRoute()}/ldap/certificate/public`,2495 {2496 method: 'post',2497 body: formData,2498 },2499 );2500 };2501 uploadPrivateLdapCertificate = (fileData: File) => {2502 const formData = new FormData();2503 formData.append('certificate', fileData);2504 return this.doFetch<StatusOK>(2505 `${this.getBaseRoute()}/ldap/certificate/private`,2506 {2507 method: 'post',2508 body: formData,2509 },2510 );2511 };2512 uploadIdpSamlCertificate = (fileData: File) => {2513 const formData = new FormData();2514 formData.append('certificate', fileData);2515 return this.doFetch<StatusOK>(2516 `${this.getBaseRoute()}/saml/certificate/idp`,2517 {2518 method: 'post',2519 body: formData,2520 },2521 );2522 };2523 deletePublicSamlCertificate = () => {2524 return this.doFetch<StatusOK>(2525 `${this.getBaseRoute()}/saml/certificate/public`,2526 {method: 'delete'},2527 );2528 };2529 deletePrivateSamlCertificate = () => {2530 return this.doFetch<StatusOK>(2531 `${this.getBaseRoute()}/saml/certificate/private`,2532 {method: 'delete'},2533 );2534 };2535 deletePublicLdapCertificate = () => {2536 return this.doFetch<StatusOK>(2537 `${this.getBaseRoute()}/ldap/certificate/public`,2538 {method: 'delete'},2539 );2540 };2541 deletePrivateLdapCertificate = () => {2542 return this.doFetch<StatusOK>(2543 `${this.getBaseRoute()}/ldap/certificate/private`,2544 {method: 'delete'},2545 );2546 };2547 deleteIdpSamlCertificate = () => {2548 return this.doFetch<StatusOK>(2549 `${this.getBaseRoute()}/saml/certificate/idp`,2550 {method: 'delete'},2551 );2552 };2553 testElasticsearch = (config: ClientConfig) => {2554 return this.doFetch<StatusOK>(2555 `${this.getBaseRoute()}/elasticsearch/test`,2556 {method: 'post', body: JSON.stringify(config)},2557 );2558 };2559 purgeElasticsearchIndexes = () => {2560 return this.doFetch<StatusOK>(2561 `${this.getBaseRoute()}/elasticsearch/purge_indexes`,2562 {method: 'post'},2563 );2564 };2565 purgeBleveIndexes = () => {2566 return this.doFetch<StatusOK>(2567 `${this.getBaseRoute()}/bleve/purge_indexes`,2568 {method: 'post'},2569 );2570 };2571 uploadLicense = (fileData: File) => {2572 this.trackEvent('api', 'api_license_upload');2573 const formData = new FormData();2574 formData.append('license', fileData);2575 const request: any = {2576 method: 'post',2577 body: formData,2578 };2579 if (formData.getBoundary) {2580 request.headers = {2581 'Content-Type': `multipart/form-data; boundary=${formData.getBoundary()}`,2582 };2583 }2584 return this.doFetch<License>(2585 `${this.getBaseRoute()}/license`,2586 request,2587 );2588 };2589 removeLicense = () => {2590 return this.doFetch<StatusOK>(2591 `${this.getBaseRoute()}/license`,2592 {method: 'delete'},2593 );2594 };2595 getAnalytics = (name = 'standard', teamId = '') => {2596 return this.doFetch<AnalyticsRow[]>(2597 `${this.getBaseRoute()}/analytics/old${buildQueryString({name, team_id: teamId})}`,2598 {method: 'get'},2599 );2600 };2601 // Role Routes2602 getRole = (roleId: string) => {2603 return this.doFetch<Role>(2604 `${this.getRolesRoute()}/${roleId}`,2605 {method: 'get'},2606 );2607 };2608 getRoleByName = (roleName: string) => {2609 return this.doFetch<Role>(2610 `${this.getRolesRoute()}/name/${roleName}`,2611 {method: 'get'},2612 );2613 };2614 getRolesByNames = (rolesNames: string[]) => {2615 return this.doFetch<Role[]>(2616 `${this.getRolesRoute()}/names`,2617 {method: 'post', body: JSON.stringify(rolesNames)},2618 );2619 };2620 patchRole = (roleId: string, rolePatch: Partial<Role>) => {2621 return this.doFetch<Role>(2622 `${this.getRolesRoute()}/${roleId}/patch`,2623 {method: 'put', body: JSON.stringify(rolePatch)},2624 );2625 };2626 // Scheme Routes2627 getSchemes = (scope = '', page = 0, perPage = PER_PAGE_DEFAULT) => {2628 return this.doFetch<Scheme[]>(2629 `${this.getSchemesRoute()}${buildQueryString({scope, page, per_page: perPage})}`,2630 {method: 'get'},2631 );2632 };2633 createScheme = (scheme: Scheme) => {2634 this.trackEvent('api', 'api_schemes_create');2635 return this.doFetch<Scheme>(2636 `${this.getSchemesRoute()}`,2637 {method: 'post', body: JSON.stringify(scheme)},2638 );2639 };2640 getScheme = (schemeId: string) => {2641 return this.doFetch<Scheme>(2642 `${this.getSchemesRoute()}/${schemeId}`,2643 {method: 'get'},2644 );2645 };2646 deleteScheme = (schemeId: string) => {2647 this.trackEvent('api', 'api_schemes_delete');2648 return this.doFetch<StatusOK>(2649 `${this.getSchemesRoute()}/${schemeId}`,2650 {method: 'delete'},2651 );2652 };2653 patchScheme = (schemeId: string, schemePatch: Partial<Scheme>) => {2654 this.trackEvent('api', 'api_schemes_patch', {scheme_id: schemeId});2655 return this.doFetch<Scheme>(2656 `${this.getSchemesRoute()}/${schemeId}/patch`,2657 {method: 'put', body: JSON.stringify(schemePatch)},2658 );2659 };2660 getSchemeTeams = (schemeId: string, page = 0, perPage = PER_PAGE_DEFAULT) => {2661 return this.doFetch<Team[]>(2662 `${this.getSchemesRoute()}/${schemeId}/teams${buildQueryString({page, per_page: perPage})}`,2663 {method: 'get'},2664 );2665 };2666 getSchemeChannels = (schemeId: string, page = 0, perPage = PER_PAGE_DEFAULT) => {2667 return this.doFetch<Channel[]>(2668 `${this.getSchemesRoute()}/${schemeId}/channels${buildQueryString({page, per_page: perPage})}`,2669 {method: 'get'},2670 );2671 };2672 // Plugin Routes - EXPERIMENTAL - SUBJECT TO CHANGE2673 uploadPlugin = async (fileData: File, force = false) => {2674 this.trackEvent('api', 'api_plugin_upload');2675 const formData = new FormData();2676 if (force) {2677 formData.append('force', 'true');2678 }2679 formData.append('plugin', fileData);2680 const request: any = {2681 method: 'post',2682 body: formData,2683 };2684 if (formData.getBoundary) {2685 request.headers = {2686 'Content-Type': `multipart/form-data; boundary=${formData.getBoundary()}`,2687 };2688 }2689 return this.doFetch<PluginManifest>(2690 this.getPluginsRoute(),2691 request,2692 );2693 };2694 installPluginFromUrl = (pluginDownloadUrl: string, force = false) => {2695 this.trackEvent('api', 'api_install_plugin');2696 const queryParams = {plugin_download_url: pluginDownloadUrl, force};2697 return this.doFetch<PluginManifest>(2698 `${this.getPluginsRoute()}/install_from_url${buildQueryString(queryParams)}`,2699 {method: 'post'},2700 );2701 };2702 getPlugins = () => {2703 return this.doFetch<PluginsResponse>(2704 this.getPluginsRoute(),2705 {method: 'get'},2706 );2707 };2708 getMarketplacePlugins = (filter: string, localOnly = false) => {2709 return this.doFetch<MarketplacePlugin[]>(2710 `${this.getPluginsMarketplaceRoute()}${buildQueryString({filter: filter || '', local_only: localOnly})}`,2711 {method: 'get'},2712 );2713 }2714 installMarketplacePlugin = (id: string, version: string) => {2715 this.trackEvent('api', 'api_install_marketplace_plugin');2716 return this.doFetch<MarketplacePlugin>(2717 `${this.getPluginsMarketplaceRoute()}`,2718 {method: 'post', body: JSON.stringify({id, version})},2719 );2720 }2721 // This function belongs to the Apps Framework feature.2722 // Apps Framework feature is experimental, and this function is susceptible2723 // to breaking changes without pushing the major version of this package.2724 getMarketplaceApps = (filter: string) => {2725 return this.doFetch<MarketplaceApp[]>(2726 `${this.getAppsProxyRoute()}/api/v1/marketplace${buildQueryString({filter: filter || ''})}`,2727 {method: 'get'},2728 );2729 }2730 getPluginStatuses = () => {2731 return this.doFetch<PluginStatus[]>(2732 `${this.getPluginsRoute()}/statuses`,2733 {method: 'get'},2734 );2735 };2736 removePlugin = (pluginId: string) => {2737 return this.doFetch<StatusOK>(2738 this.getPluginRoute(pluginId),2739 {method: 'delete'},2740 );2741 };2742 getWebappPlugins = () => {2743 return this.doFetch<ClientPluginManifest[]>(2744 `${this.getPluginsRoute()}/webapp`,2745 {method: 'get'},2746 );2747 };2748 enablePlugin = (pluginId: string) => {2749 return this.doFetch<StatusOK>(2750 `${this.getPluginRoute(pluginId)}/enable`,2751 {method: 'post'},2752 );2753 };2754 disablePlugin = (pluginId: string) => {2755 return this.doFetch<StatusOK>(2756 `${this.getPluginRoute(pluginId)}/disable`,2757 {method: 'post'},2758 );2759 };2760 // Groups2761 linkGroupSyncable = (groupID: string, syncableID: string, syncableType: string, patch: SyncablePatch) => {2762 return this.doFetch<GroupSyncable>(2763 `${this.getGroupRoute(groupID)}/${syncableType}s/${syncableID}/link`,2764 {method: 'post', body: JSON.stringify(patch)},2765 );2766 };2767 unlinkGroupSyncable = (groupID: string, syncableID: string, syncableType: string) => {2768 return this.doFetch<StatusOK>(2769 `${this.getGroupRoute(groupID)}/${syncableType}s/${syncableID}/link`,2770 {method: 'delete'},2771 );2772 };2773 getGroupSyncables = (groupID: string, syncableType: string) => {2774 return this.doFetch<GroupSyncable[]>(2775 `${this.getGroupRoute(groupID)}/${syncableType}s`,2776 {method: 'get'},2777 );2778 };2779 getGroup = (groupID: string) => {2780 return this.doFetch<Group>(2781 this.getGroupRoute(groupID),2782 {method: 'get'},2783 );2784 };2785 getGroupStats = (groupID: string) => {2786 return this.doFetch<Group>(2787 `${this.getGroupRoute(groupID)}/stats`,2788 {method: 'get'},2789 );2790 };2791 getGroups = (filterAllowReference = false, page = 0, perPage = PER_PAGE_DEFAULT) => {2792 return this.doFetch<Group[]>(2793 `${this.getGroupsRoute()}${buildQueryString({filter_allow_reference: filterAllowReference, page, per_page: perPage})}`,2794 {method: 'get'},2795 );2796 };2797 getGroupsByUserId = (userID: string) => {2798 return this.doFetch<Group[]>(2799 `${this.getUsersRoute()}/${userID}/groups`,2800 {method: 'get'},2801 );2802 };2803 getGroupsNotAssociatedToTeam = (teamID: string, q = '', page = 0, perPage = PER_PAGE_DEFAULT) => {2804 this.trackEvent('api', 'api_groups_get_not_associated_to_team', {team_id: teamID});2805 return this.doFetch<Group[]>(2806 `${this.getGroupsRoute()}${buildQueryString({not_associated_to_team: teamID, page, per_page: perPage, q, include_member_count: true})}`,2807 {method: 'get'},2808 );2809 };2810 getGroupsNotAssociatedToChannel = (channelID: string, q = '', page = 0, perPage = PER_PAGE_DEFAULT, filterParentTeamPermitted = false) => {2811 this.trackEvent('api', 'api_groups_get_not_associated_to_channel', {channel_id: channelID});2812 const query = {2813 not_associated_to_channel: channelID,2814 page,2815 per_page: perPage,2816 q,2817 include_member_count: true,2818 filter_parent_team_permitted: filterParentTeamPermitted,2819 };2820 return this.doFetch<Group[]>(2821 `${this.getGroupsRoute()}${buildQueryString(query)}`,2822 {method: 'get'},2823 );2824 };2825 // This function belongs to the Apps Framework feature.2826 // Apps Framework feature is experimental, and this function is susceptible2827 // to breaking changes without pushing the major version of this package.2828 executeAppCall = async (call: AppCallRequest, type: AppCallType) => {2829 const callCopy: AppCallRequest = {2830 ...call,2831 path: `${call.path}/${type}`,2832 context: {2833 ...call.context,2834 user_agent: 'webapp',2835 },2836 };2837 return this.doFetch<AppCallResponse>(2838 `${this.getAppsProxyRoute()}/api/v1/call`,2839 {method: 'post', body: JSON.stringify(callCopy)},2840 );2841 }2842 // This function belongs to the Apps Framework feature.2843 // Apps Framework feature is experimental, and this function is susceptible2844 // to breaking changes without pushing the major version of this package.2845 getAppsBindings = async (userID: string, channelID: string, teamID: string) => {2846 const params = {2847 user_id: userID,2848 channel_id: channelID,2849 team_id: teamID,2850 user_agent: 'webapp',2851 };2852 return this.doFetch(2853 `${this.getAppsProxyRoute()}/api/v1/bindings${buildQueryString(params)}`,2854 {method: 'get'},2855 );2856 }2857 getGroupsAssociatedToTeam = (teamID: string, q = '', page = 0, perPage = PER_PAGE_DEFAULT, filterAllowReference = false) => {2858 this.trackEvent('api', 'api_groups_get_associated_to_team', {team_id: teamID});2859 return this.doFetch<{2860 groups: Group[];2861 total_group_count: number;2862 }>(2863 `${this.getBaseRoute()}/teams/${teamID}/groups${buildQueryString({page, per_page: perPage, q, include_member_count: true, filter_allow_reference: filterAllowReference})}`,2864 {method: 'get'},2865 );2866 };2867 getGroupsAssociatedToChannel = (channelID: string, q = '', page = 0, perPage = PER_PAGE_DEFAULT, filterAllowReference = false) => {2868 this.trackEvent('api', 'api_groups_get_associated_to_channel', {channel_id: channelID});2869 return this.doFetch<{2870 groups: Group[];2871 total_group_count: number;2872 }>(2873 `${this.getBaseRoute()}/channels/${channelID}/groups${buildQueryString({page, per_page: perPage, q, include_member_count: true, filter_allow_reference: filterAllowReference})}`,2874 {method: 'get'},2875 );2876 };2877 getAllGroupsAssociatedToTeam = (teamID: string, filterAllowReference = false, includeMemberCount = false) => {2878 return this.doFetch<GroupsWithCount>(2879 `${this.getBaseRoute()}/teams/${teamID}/groups${buildQueryString({paginate: false, filter_allow_reference: filterAllowReference, include_member_count: includeMemberCount})}`,2880 {method: 'get'},2881 );2882 };2883 getAllGroupsAssociatedToChannelsInTeam = (teamID: string, filterAllowReference = false) => {2884 return this.doFetch<{2885 groups: RelationOneToOne<Channel, Group>;2886 }>(2887 `${this.getBaseRoute()}/teams/${teamID}/groups_by_channels${buildQueryString({paginate: false, filter_allow_reference: filterAllowReference})}`,2888 {method: 'get'},2889 );2890 };2891 getAllGroupsAssociatedToChannel = (channelID: string, filterAllowReference = false, includeMemberCount = false) => {2892 return this.doFetch<GroupsWithCount>(2893 `${this.getBaseRoute()}/channels/${channelID}/groups${buildQueryString({paginate: false, filter_allow_reference: filterAllowReference, include_member_count: includeMemberCount})}`,2894 {method: 'get'},2895 );2896 };2897 patchGroupSyncable = (groupID: string, syncableID: string, syncableType: string, patch: SyncablePatch) => {2898 return this.doFetch<GroupSyncable>(2899 `${this.getGroupRoute(groupID)}/${syncableType}s/${syncableID}/patch`,2900 {method: 'put', body: JSON.stringify(patch)},2901 );2902 };2903 patchGroup = (groupID: string, patch: GroupPatch) => {2904 return this.doFetch<Group>(2905 `${this.getGroupRoute(groupID)}/patch`,2906 {method: 'put', body: JSON.stringify(patch)},2907 );2908 };2909 // Redirect Location2910 getRedirectLocation = (urlParam: string) => {2911 if (!urlParam.length) {2912 return Promise.resolve();2913 }2914 const url = `${this.getRedirectLocationRoute()}${buildQueryString({url: urlParam})}`;2915 return this.doFetch<{2916 location: string;2917 }>(url, {method: 'get'});2918 };2919 // Bot Routes2920 createBot = (bot: Bot) => {2921 return this.doFetch<Bot>(2922 `${this.getBotsRoute()}`,2923 {method: 'post', body: JSON.stringify(bot)},2924 );2925 }2926 patchBot = (botUserId: string, botPatch: BotPatch) => {2927 return this.doFetch<Bot>(2928 `${this.getBotRoute(botUserId)}`,2929 {method: 'put', body: JSON.stringify(botPatch)},2930 );2931 }2932 getBot = (botUserId: string) => {2933 return this.doFetch<Bot>(2934 `${this.getBotRoute(botUserId)}`,2935 {method: 'get'},2936 );2937 }2938 getBots = (page = 0, perPage = PER_PAGE_DEFAULT) => {2939 return this.doFetch<Bot[]>(2940 `${this.getBotsRoute()}${buildQueryString({page, per_page: perPage})}`,2941 {method: 'get'},2942 );2943 }2944 getBotsIncludeDeleted = (page = 0, perPage = PER_PAGE_DEFAULT) => {2945 return this.doFetch<Bot[]>(2946 `${this.getBotsRoute()}${buildQueryString({include_deleted: true, page, per_page: perPage})}`,2947 {method: 'get'},2948 );2949 }2950 getBotsOrphaned = (page = 0, perPage = PER_PAGE_DEFAULT) => {2951 return this.doFetch<Bot[]>(2952 `${this.getBotsRoute()}${buildQueryString({only_orphaned: true, page, per_page: perPage})}`,2953 {method: 'get'},2954 );2955 }2956 disableBot = (botUserId: string) => {2957 return this.doFetch<Bot>(2958 `${this.getBotRoute(botUserId)}/disable`,2959 {method: 'post'},2960 );2961 }2962 enableBot = (botUserId: string) => {2963 return this.doFetch<Bot>(2964 `${this.getBotRoute(botUserId)}/enable`,2965 {method: 'post'},2966 );2967 }2968 assignBot = (botUserId: string, newOwnerId: string) => {2969 return this.doFetch<Bot>(2970 `${this.getBotRoute(botUserId)}/assign/${newOwnerId}`,2971 {method: 'post'},2972 );2973 }2974 // Cloud routes2975 getCloudProducts = () => {2976 return this.doFetch<Product[]>(2977 `${this.getCloudRoute()}/products`, {method: 'get'},2978 );2979 };2980 createPaymentMethod = async () => {2981 return this.doFetch(2982 `${this.getCloudRoute()}/payment`,2983 {method: 'post'},2984 );2985 }2986 getCloudCustomer = () => {2987 return this.doFetch<CloudCustomer>(2988 `${this.getCloudRoute()}/customer`, {method: 'get'},2989 );2990 }2991 updateCloudCustomer = (customerPatch: CloudCustomerPatch) => {2992 return this.doFetch<CloudCustomer>(2993 `${this.getCloudRoute()}/customer`,2994 {method: 'put', body: JSON.stringify(customerPatch)},2995 );2996 }2997 updateCloudCustomerAddress = (address: Address) => {2998 return this.doFetch<CloudCustomer>(2999 `${this.getCloudRoute()}/customer/address`,3000 {method: 'put', body: JSON.stringify(address)},3001 );3002 }3003 confirmPaymentMethod = async (stripeSetupIntentID: string) => {3004 return this.doFetch(3005 `${this.getCloudRoute()}/payment/confirm`,3006 {method: 'post', body: JSON.stringify({stripe_setup_intent_id: stripeSetupIntentID})},3007 );3008 }3009 subscribeCloudProduct = (productId: string) => {3010 return this.doFetch<CloudCustomer>(3011 `${this.getCloudRoute()}/cloud/subscription`,3012 {method: 'put', body: JSON.stringify({product_id: productId})},3013 );3014 }3015 getSubscription = () => {3016 return this.doFetch<Subscription>(3017 `${this.getCloudRoute()}/subscription`,3018 {method: 'get'},...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Barack_Obama');3page.fetch(function(err, data){4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var wptools = require('wptools');11var page = wptools.page('Barack_Obama');12page.fetch(function(err, data){13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var wptools = require('wptools');20var page = wptools.page('Barack_Obama');21page.fetch(function(err, data){22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28var wptools = require('wptools');29var page = wptools.page('Barack_Obama');30page.fetch(function(err, data){31 if (err) {32 console.log(err);33 } else {34 console.log(data);35 }36});37var wptools = require('wptools');38var page = wptools.page('Barack_Obama');39page.fetch(function(err, data){40 if (err) {41 console.log(err);42 } else {43 console.log(data);44 }45});46var wptools = require('wptools');47var page = wptools.page('Barack_Obama');48page.fetch(function(err, data){49 if (err) {50 console.log(err);51 } else {52 console.log(data);53 }54});55var wptools = require('wptools');56var page = wptools.page('Barack_Obama');57page.fetch(function(err, data){58 if (err) {59 console.log(err);60 } else {61 console.log(data);62 }63});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'API Key');3wpt.runTest(url, function(err, data) {4 console.log(data);5 wpt.getTestResults(data.data.testId, function(err, data) {6 console.log(data);7 });8});

Full Screen

Using AI Code Generation

copy

Full Screen

1 headers: {2 },3})4 .then((response) => {5 console.log(response);6 })7 .catch((error) => {8 console.log(error);9 });10arrayBuffer() - Returns a promise that resolves with an ArrayBuffer11blob() - Returns a promise that resolves with a Blob12formData() - Returns a promise that resolves with a FormData object13json() - Returns a promise that resolves with a JSON object14text() - Returns a promise that resolves with a string15 headers: {16 },17})18 .then((response) => {19 console.log(response);20 return response.json();21 })22 .then((data) => {23 console.log(data);24 })25 .catch((error) => {26 console.log(error);27 });28 headers: {29 },30})31 .then((response) => {32 console.log(response);33 return response.json();34 })35 .then((data) => {36 console.log(data);37 })38 .catch((error) => {39 console.log(error);40 });

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('wpt');2const wptClient = new wpt('your api key');3wptClient.doFetch('www.google.com', 'json', function(err, data) {4 console.log(data);5});6const wpt = require('wpt');7const wptClient = new wpt('your api key');8wptClient.doFetch('www.google.com', 'xml', function(err, data) {9 console.log(data);10});11const wpt = require('wpt');12const wptClient = new wpt('your api key');13wptClient.doFetch('www.google.com', 'xml', function(err, data) {14 console.log(data);15});16const wpt = require('wpt');17const wptClient = new wpt('your api key');18wptClient.doFetch('www.google.com', 'json', function(err, data) {19 console.log(data);20});21const wpt = require('wpt');22const wptClient = new wpt('your api key');23wptClient.doFetch('www.google.com', 'xml', function(err, data) {24 console.log(data);25});26const wpt = require('wpt');27const wptClient = new wpt('your api key');28wptClient.doFetch('www.google.com', 'xml', function(err, data) {29 console.log(data);30});31const wpt = require('wpt');32const wptClient = new wpt('your api key');33wptClient.doFetch('www.google.com', 'json', function(err, data) {34 console.log(data);35});36const wpt = require('wpt');37const wptClient = new wpt('your api key');38wptClient.doFetch('www.google.com', 'xml', function(err, data) {

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful