forked from jameswh3/MW-Toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-ConversationTranscriptsViaAPI.ps1
More file actions
40 lines (34 loc) · 1.98 KB
/
Get-ConversationTranscriptsViaAPI.ps1
File metadata and controls
40 lines (34 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function Get-ConversationTranscriptsViaAPI {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true, Position=0, HelpMessage="Enter the Azure AD application client ID")]
[string]$ClientId,
[Parameter(Mandatory=$true, Position=1, HelpMessage="Enter the client secret for authentication")]
[string]$ClientSecret,
[Parameter(Mandatory=$true, Position=2, HelpMessage="Enter your Dynamics 365 organization URL (e.g., contoso.crm.dynamics.com)")]
[string]$OrgUrl,
[Parameter(Mandatory=$true, Position=3, HelpMessage="Enter your tenant domain (e.g., contoso.onmicrosoft.com)")]
[string]$TenantDomain,
[Parameter(Mandatory=$false, HelpMessage="Specify additional fields to retrieve")]
[string[]]$FieldList="content,createdon,conversationtranscriptid,_bot_conversationtranscriptid_value,metadata",
[Parameter(Mandatory=$false, HelpMessage="Start date for filtering conversation transcripts (format: yyyy-MM-dd)")]
[datetime]$StartDate,
[Parameter(Mandatory=$false, HelpMessage="End date for filtering conversation transcripts (format: yyyy-MM-dd)")]
[datetime]$EndDate
)
BEGIN {
$tokenUrl = "https://login.microsoftonline.com/$TenantDomain/oauth2/v2.0/token"
$token = Invoke-RestMethod -Uri $tokenUrl `
-Method Post `
-Body @{grant_type="client_credentials"; client_id="$ClientId"; client_secret="$ClientSecret"; scope="https://$OrgUrl/.default"} `
-ContentType 'application/x-www-form-urlencoded'
}
PROCESS {
#get list of conversation transcripts
$response=Invoke-RestMethod -Uri "https://$OrgUrl/api/data/v9.2/conversationtranscripts?`$select=$FieldList&`$filter=createdon ge $($StartDate.ToString("yyyy-MM-dd")) and createdon le $($EndDate.ToString("yyyy-MM-dd"))" `
-Headers @{Authorization = "Bearer $($token.access_token)"}
}
END {
return $response.value
}
}