-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_to_csv.ps1
More file actions
22 lines (19 loc) · 1.23 KB
/
export_to_csv.ps1
File metadata and controls
22 lines (19 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
######### Secrets #########
$apiKey = "your API token"
$apiUri = "https://your_subdomain.syncromsp.com/api/v1/"
######### Secrets #########
$query = [System.Web.HTTPUtility]::UrlEncode($(Read-Host "Please enter client name"))
$companySyncroID = (Invoke-RestMethod -Uri "$apiUri/customers?query=$query" -Method Get -Header @{ "Authorization" = "Bearer "+$apiKey } -ContentType "application/json")[0].customers.id
if ($companySyncroID -eq $null) {
write-host "Client $($Customer.Name) not found SyncroMSP" -ForegroundColor Red
} else {
$Syncro = (Invoke-RestMethod -Method Get -Uri "$apiUri/contacts?customer_id=$companySyncroID" -Header @{ "Authorization" = "Bearer "+$apiKey } -ContentType "application/json")
$allusersSyncro = $syncro.contacts
$totalPages = $Syncro.meta.total_pages
if ($totalPages -ne 1) {
for($i=2; $i -le $totalPages; $i++){
$allusersSyncro += (Invoke-RestMethod -Method Get -Uri "$apiUri/contacts?customer_id=$companySyncroID&page=$i" -Header @{ "Authorization" = "Bearer "+$apiKey } -ContentType "application/json").contacts
}
}
$allusersSyncro | Export-Csv -Path "$PSScriptRoot\Contacts_for_$query.csv" -NoTypeInformation
}