Skip to content

Commit b064570

Browse files
authored
Create Create-Action1DataSource.ps1
1 parent 9d9d98c commit b064570

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

Create-Action1DataSource.ps1

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# The below script is used to create an Action1 data_source object. The API is new and bugged as of 3/10/2022 and is unable to complete these actions just yet
2+
3+
# Authenticate to Action1 API
4+
$Url = "https://app.action1.com/api/3.0"
5+
$Body = @{
6+
client_id="[email protected]"
7+
client_secret="00000000000000000000000000000000"
8+
} # End Body
9+
$Response = Invoke-WebRequest -Uri "$Url/oauth2/token" -ContentType "application/x-www-form-urlencoded" -Method POST -Body $Body
10+
11+
12+
# Get the JWT Token from above authentication and create header
13+
$JWT = $Response.Content | ConvertFrom-Json | Select-Object -ExpandProperty access_token
14+
$Header = @{
15+
Authorization="Bearer $JWT"
16+
} # End Token
17+
18+
19+
# Check if data source already exists
20+
# ORG-ID CAN ONLY BE SET TO ALL LAST CHECKED 3/10/2022
21+
$DataSource = Invoke-WebRequest -Uri "$Url/data_sources/all/your-data-source-id" -Headers $Header -Method GET -ContentType "application/x-www-form-urlencoded" -ErrorVariable Error
22+
23+
If ($Error) {
24+
25+
# Data source should only be created onece then updated after that. If the data source does not exist this section creates it
26+
$Columns = @{}
27+
$Columns.ProcessName
28+
$Columns.Id
29+
$Columns.MachineName
30+
31+
$PostData = @{
32+
id = "your-data-source-id"
33+
type = "DataSource"
34+
name = "Your Data Source Name"
35+
builtin = "no"
36+
self = "$Url/data_sources/all/your-data-source-id"
37+
status = "Draft"
38+
description = "Description of your data source"
39+
language = "PowerShell"
40+
script_text = 'Get-Process # Your script here should return a PSObject. You can define the property values you want returned using the $Columns variable above'
41+
columns = $Columns
42+
} # End PostData
43+
$StoreResult = Invoke-WebRequest -Uri "$Url/data_sources/all" -Headers $Header -Method POST -ContentType "application/x-www-form-urlencoded" -Body ($PostData | ConvertTo-Json)
44+
45+
} # End If
46+
Else {
47+
48+
# This updates an already existing data_source because it does not need to be created again
49+
$PublishedResult = Invoke-WebRequest -Uri "$Url/data_sources/all/your-data-source-id" -Headers $Header -Method PATCH -ContentType "application/x-www-form-urlencoded"
50+
51+
} # End Else

0 commit comments

Comments
 (0)