Hi I am trying to import assets into Insight using there API.
I have worked out how to view objects but I'm a little lost on how to add new objects.
I can't work out how to attach the JSON to invoke-restMethod.
I have my sample input JSON like this.
$InputJSON = @"
{
"objectTypeId": $6,
"attributes": [{
"objectTypeAttributeId": 22,
"objectAttributeValues": [{
"Default": "$room_name"
}],
"attributes": [{
"objectTypeAttributeId": 46,
"objectAttributeValues": [{
"Default": "$calendar_name"
}]
}]
}
"@
And I'm trying to add it to this call.
$InsightURL = "https://insight-api.riada.io/rest/insight/1.0/object/create"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;
$Headers = @{
Authorization = "Bearer e6292...597f"
'Content-Type' = 'application/json'
}
$r = Invoke-RestMethod -Uri $InsightURL -Headers $headers -Method POST
Is it supposed to go in the headers? Is there a particular way to attach it?
Any help would be awesome or if anyone has a script example that they could show me that would be even better!
I'm using cloud version if that matters.
To append your JSON to the Post request you can use the Body parameter of Invoke-RestMethod like this:
$r = Invoke-RestMethod -Uri $InsightURL -Headers $headers -Method POST -Body $InputJSON
I did try that but had an error so I reduced it down to its simplest form and found out that I had
"objectTypeId": $6
instead of
"objectTypeId": 6
But I still get a error
Invoke-RestMethod : {"errorMessages":[],"errors":{"rlabs-insight-attribute-22":"At least one value must be set"}}
So this is what my object looks like. (Removed the link to parent object for now.
As you can see I am just going to import some zoom rooms and link the assets between the rooms, and the hardware in said room.
This is my simplified script, trying to just create a object with a 'test' label and nothing else.
$InputJSON = @"
{
"objectTypeId": 6,
"attributes": [{
"objectTypeAttributeId": 22,
"objectAttributeValues": [{
"Default": "Test"
}]
}]
}
"@
$InsightURL = "https://insight-api.riada.io/rest/insight/1.0/object/create"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;
$Headers = @{
Authorization = "Bearer e62...597f"
'Content-Type' = 'application/json'
}
Invoke-RestMethod -Uri $InsightURL -Headers $Headers -Body $InputJSON -Method POST
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I got it working on a completly fresh cloud instance, so my id's are 1 fore the objecttype and 2 for the atrribute.
Here is my JSON:
$InputJSON = @"
{
"objectTypeId": 1,
"attributes": [{
"objectTypeAttributeId": 2,
"objectAttributeValues": [{
"value": "Demo"
}]
}]
}
"@
You need to write
"value": "Demo"
"value" instead of "Default" <- this in the documentation is reffering to the type of the attribute which can be a "default" like text, interger, float and so on or some special attribute like a jira user or project.
And here is the call which was successful:
$InsightURL = "https://insight-api.riada.io/rest/insight/1.0/object/create"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;
$Headers = @{
Authorization = "Bearer 6ed...0a85f"
'Content-Type' = 'application/json'
}
$r = Invoke-RestMethod -Uri $InsightURL -Headers $headers -Method POST -Body $InputJSON
Hope this will help you.
Regards
Tobias
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you so much!
Been going crazy trying to work it out.
I looked back at my revisions because I was sure that I used what they had and I had capitalized 'Value'.
This will get me through the eval stage to decide if we want to run with it, but i am not looking forward to writing these scripts where i need to work off the ID instead of the name.
Might have to build a module if we go with this application.
Again, thanks heaps for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am thinking about to write my own groovy module to get and set values. In groovy (for the server version) it is very hard for beginners to understand the connection between the different "Beans" you have to use.
If you want to stay in the powershell environment, do you know https://atlassianps.org/ ?
Maybe you can start using this and extend this one for insight.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry not sure why I have only just seen your reply.
I will stay in PS, I have seen that module but I was thinking of creating my one for insight which someone else could then merge. I'll link here if we get the green light to use jira
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey there,
I've started working on the same requirements, but getting a 415 error.
I've repeated your example.
Did you ever come across this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.