Skip to content

Commit

Permalink
Split Manage and Automate queries, added handling of null field value…
Browse files Browse the repository at this point in the history
…s, updated samples
  • Loading branch information
derpenstiltskin committed May 18, 2022
1 parent d5422d3 commit a744be6
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 177 deletions.
34 changes: 0 additions & 34 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,69 +1,35 @@
### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Dustin Riley. All rights reserved.
Copyright (c) 2021-2022 Dustin Riley. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
58 changes: 38 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,82 @@
# Connect Power BI to ConnectWise Manage and Automate
# Power BI Queries for ConnectWise Manage and Automate

This function will query the specified ConnectWise Manage or Automate API based on the parameters you pass to the function. To be able to use the CWApiRequest function provided, you must replace the API placeholder values listed below.
These Power Queries will perform requests against the ConnectWise Manage and Automate REST APIs.

## Features

- Handles authentication to the ConnectWise Manage and Automate REST APIs
- Handles retrieving access token from ConnectWise Automate
- Automatically manages API request paging, no action needed to retrieve over 1000 records
- Option to automatically expand all return columns that contain records
- Support for any condition, filtering, sorting the API supports via query string
- Support for any condition, filtering, sorting the API supports via query string
- Handles query responses with null value fields
- Able to be pushed to Power BI online and have the dataset automatically refresh


## Parameters

- Product (text) - ConnectWise Product API you will be querying (ex: "manage")
- ApiEndpoint (text) - API endpoint you will be querying (ex: "service/tickets")
- Resource (text) - API resource you will be querying (Manage ex: "service/tickets"; Automate ex: "computers)
- Query (record) - Record of query string parameters to send to the API (ex: [conditions='closedFlag=false'])
- ExpandAll (logical) - Set to true if you want column records automatically expanded (ex: true)

## API Placeholders
## ConnectWise Manage API Placeholders

Replace these with your values, a couple are in multiple spots.
Replace these with your values.

- CWD_CLIENTID - This is your ClientID obtained from the ConnectWise Developer Network: https://developer.connectwise.com
- CWA_USERNAME - Username for integrator account setup in ConnectWise Automate
- CWA_PASSWORD - Password for integrator account setup in ConnectWise Automate
- CWA_API_URL - URL for your ConnectWise Automate instance API (ex: "https://demo.hostedrmm.com/cwa/api/v1/")
- CWM_AUTH - This value is a base64 encoding of YourCWMCompany+YourApiPublicKey:YourApiPrivateKey
- CWM_API_URL - URL to your ConnectWise Manage instance API (ex: "https://api-na.myconnectwise.net/v4_6_release/apis/3.0/")
- _CWMANAGE_CLIENTID_ - This is the ClientID obtained from the ConnectWise Developer Network: https://developer.connectwise.com
- _CWMANAGE_COMPANY_ - Company value for your ConnectWise Manage instance
- _CWMANAGE_PUBKEY_ - Public key for your ConnectWise Manage API Key
- _CWMANAGE_PRIVKEY_ - Private key for your ConnectWise Manage API Key
- _CWMANAGE_API_URL_ - URL for your ConnectWise Manage API instance (ex: "https://api-na.myconnectwise.net/v4_6_release/apis/3.0/")

## ConnectWise Automate API Placeholders

Replace these with your values.

- _CWAUTOMATE_CLIENTID_ - This is the ClientID obtained from the ConnectWise Developer Network: https://developer.connectwise.com
- _CWAUTOMATE_USERNAME_ - Username for an integrator account in ConnectWise Automate
- _CWAUTOMATE_PASSWORD_ - Password for an integrator account in ConnectWise Automate
- _CWAAUTOMATE_API_URL_ - URL for your ConnectWise Automate API instance (ex: "https://demo.hostedrmm.com/cwa/api/v1/")

## Power BI Online

This function can be used for datasets that are pushed to Power BI Online. The only option you will need to change once you have the dataset in Power BI online, is to modify the authentication settings for the dataset and have it to skip Authentication Checks. Once you have done that, the dataset can be scheduled to refresh automatically.
These queries can be used for datasets that are pushed to Power BI Online. The only option you will need to change once you have the dataset in Power BI online, is to modify the authentication settings for the dataset to have it to Skip Authentication Checks. With that set, the dataset can be scheduled to refresh automatically.

## Download

[Project Releases](https://github.com/derpenstiltskin/connectwise-powerbi/releases)

## How To Use

Grab the latest release from above. Then create a new query in Power BI called CWApiRequest and copy/paste the contents of the file CWApiRequest.pq into the query. Once that's done you can create another query that uses the CWApiRequest function. The samples below show how CWApiRequest can be used.
Grab the latest release from above

For ConnectWise Manage Queries:
- Create a query in Power BI called CWManageApiRequest
- Copy/Paste the contents of CWManageApiRequest.pq into the query
- Create a query to call CWManageApiRequest

For ConnectWise Automate Queries:
- Create a query in Power BI called CWAutomateApiRequest
- Copy/Paste the contents of CWAutomateApiRequest.pq into the query
- Create a query to call CWAutomateApiRequest

I would suggest using [Postman](https://www.postman.com/) or an equivalent REST API explorer to build your queries before using them in Power BI, as you will get better error messages with the HTTP responses.
I would suggest using [Postman](https://www.postman.com/), [Insomnia](https://insomnia.rest/) or an equivalent REST API explorer to build your queries before using them in Power BI, as you will get better error messages for debugging.

If you have already tried setting up authentication in your PBIX to your ConnectWise REST API instance, remove that as the CWApiRequest function handles authentication to the API.
If you have already tried setting up authentication in your PBIX to your ConnectWise REST API instance previously, remove that because the CWManageApiRequest and CWAutomateApiRequest queries handle authentication.

## Samples

**ConnectWise Manage**

[Get Open Service Tickets](https://github.com/derpenstiltskin/connectwise-powerbi/blob/main/samples/SAMPLE_CWM_GetOpenServiceTickets.pq)
[Get Open Service Tickets](https://github.com/derpenstiltskin/connectwise-powerbi/blob/main/samples/CWManage_GetOpenServiceTickets.pq)

**ConnectWise Automate**

[Get Location Computers](https://github.com/derpenstiltskin/connectwise-powerbi/blob/main/samples/SAMPLE_CWA_GetLocationComputers.pq)
[Get Location Computers](https://github.com/derpenstiltskin/connectwise-powerbi/blob/main/samples/CWAutomate_GetLocationComputers.pq)

## ConnectWise REST API Documentation

[ConnectWise Developer](https://developer.connectwise.com/Products/Manage/REST)
[ConnectWise Developer](https://developer.connectwise.com)

## Special Thanks

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
let
LocationComputers = let
Response = CWApiRequest(
"automate",
Response = CWAutomateApiRequest(
"computers",
[
condition = "location.name='Trenzalore'",
condition = "location.name='Home Office'",
includefields = "id,computername,location",
orderby = "computername asc"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
let
OpenServiceTickets = let
Response = CWApiRequest(
"manage",
Response = CWManageApiRequest(
"service/tickets",
[
conditions = "closedFlag=false",
Expand Down
117 changes: 0 additions & 117 deletions src/CWApiRequest.pq

This file was deleted.

Loading

0 comments on commit a744be6

Please sign in to comment.