Retrieve all Users using the API

Silly question but I can't seem to find the best way of retrieving all of the users using the API. Is there any query that can be used or do you have to create a group for everyone and query based on that group? Or query all current groups and concatenate the users of those together?

 

Thank you!

0
👍 Spot On 💡 Innovative Approach 💪 Stellar Advice ✅ Solved 🪄 Remove Kudos
Комментариев: 2

Hi Robert, welcome to the Community, happy to see you here 🙂

There are no silly questions here! You can query contacts - they will contain User info. 

Hope this helps and please get back to me if you have any further questions! 

Lisa Community Team at Wrike Wrike Product Manager Become a Wrike expert with Wrike Discover

Lisa Wrike Team member Become a Wrike expert with Wrike Discover

0
👍 Spot On 💡 Innovative Approach 💪 Stellar Advice ✅ Solved 🪄 Remove Kudos

This powershell script will get you close: 

# Define your Wrike API access token

$accessToken = ‘XXXX’ # Replace with your actual access token

 

# Set up the headers with the authorization token

$headers = @{

    'Authorization' = "Bearer $accessToken"

}

 

# Fetch all users and collaborators

$contactsResponse = Invoke-WebRequest -Uri 'https://www.wrike.com/api/v4/contacts' -Headers $headers

$contacts = ($contactsResponse.Content | ConvertFrom-Json).data

 

# Fetch all groups

$groupsResponse = Invoke-WebRequest -Uri 'https://www.wrike.com/api/v4/groups' -Headers $headers

$groups = ($groupsResponse.Content | ConvertFrom-Json).data

 

# Process the data to match users with their groups, activation status, and other fields

$userData = foreach ($user in $contacts) {

    $userGroups = $groups | Where-Object { $_.memberIds -contains $user.id }

    $status = if ($user.deleted -eq $false) { 'Activated' } else { 'Deactivated' }

    $role = $user.profiles[0].role # Assuming the role is in the first profile

 

    [PSCustomObject]@{

        Id        = $user.id

        FirstName = $user.firstName

        LastName  = $user.lastName

        Email     = $user.profiles[0].email

        Groups    = ($userGroups | ForEach-Object { $_.title }) -join ', '

        Status    = $status

        Role      = $role

        Deleted   = $user.deleted

    }

}

 

# Export the processed data to a CSV file

$userData | Export-Csv -Path $PSscriptroot/WrikeUsersAndGroups.csv -NoTypeInformation

 

Write-Host "Export completed. Check the file 'WrikeUsersAndGroups.csv'."

0
👍 Spot On 💡 Innovative Approach 💪 Stellar Advice ✅ Solved 🪄 Remove Kudos

Folllowing List for Post: Retrieve all Users using the API
[this list is visible for admins and agents only]

Вверх

Upcoming Live Sessions

Didn’t find what you were looking for? Write new post