Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Create top level object in Insight cloud via API

Gary Smith August 17, 2020

I'm trying to create a top level object via Powershell\API but the JSON in the docs doesn't seem to work no matter how i format it.

 

function New-InsightObjectType {
param(
[STRING]$APIKey,
[STRING]$ObjectSchemaID,
[STRING]$Name,
[STRING]$Description,
[STRING]$IconID
)

$URI = "https://insight-api.riada.io" + "/rest/insight/1.0/objecttype/create"

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;

$Headers = @{
Authorization = "Bearer $APIKey"
'Content-Type' = 'application/json'
}

$JSON = @"
{
"name": $Name,
"iconId": $IconID,
"objectSchemaId": $ObjectSchemaID
}
"@


Invoke-RestMethod -Uri $URI -Headers $Headers -Body $JSON -Method POST
}

New-InsightObjectType -APIKey $APIKey -Name "Rooms" -IconID "2" -ObjectSchemaID "3"

 This is the error I get when running


Invoke-RestMethod : {"errorMessages":["Unrecognized token 'Rooms': was expecting (JSON String, Number, Array, Object or token 'null', 'true'
or 'false')\n at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 2, column:
23]"],"errors":{}}
At line:28 char:1
+ Invoke-RestMethod -Uri $URI -Headers $Headers -Body $JSON -Method POS ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

 Does anyone know what is required?

1 answer

0 votes
Gary.Smith
Contributor
August 19, 2020

It was something dumb.

I needed to wrap my vars in quotes like below.

$JSON = @"
{
"name": "$Name",
"iconId": "$IconID",
"objectSchemaId": "$ObjectSchemaID"
}
"@

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events