Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Insight Cloud API Powershell

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.

 

 

1 answer

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. 

Annotation 2020-06-17 112216.png(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

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

Like Gary Smith likes this

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.

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.

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

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?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
Community showcase
Published in Jira Service Management

Why upgrade to Jira Service Management Premium?

We often have questions from folks using Jira Service Management about the benefits to using Premium. Check out this video to learn how you can unlock even more value in our Premium plan.  &nb...

189 views 1 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you