Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,296,121
Community Members
 
Community Events
165
Community Groups

Help for Insight REST API updating an Attribute

Hi,

First of all thanks to all who respond to queries here, your answers have helped me no end in working with the Jira and Insight Server REST APIs.
However, I'm currently stuck trying to update an Object's attribute. I'm currently restricted to using PowerShell to do this. I've been trying to follow the API reference here: https://insight-javadoc.riada.io/insight-javadoc-8.6/insight-rest/#objectattribute__id__put
This is the (sanitised) Object I want to update:

id : 21408
label : John Smith
objectKey : RIA-21408
avatar : @{url16=https://jira.local.com/rest/insight/1.0/objecttype/353/icon.png?size=16&uuid=708076cb-86b6-4d3e-8aae-0e3762cf4590; url48=https://jira.local.com/rest/insight/1.0/objecttype/353/icon.png?size=48&uuid=708076cb-86b6-4d3e-8aae-0e3762cf4590;
url72=https://jira.local.com/rest/insight/1.0/objecttype/353/icon.png?size=72&uuid=708076cb-86b6-4d3e-8aae-0e3762cf4590; url144=https://jira.local.com/rest/insight/1.0/objecttype/353/icon.png?size=144&uuid=708076cb-86b6-4d3e-8aae-0e3762cf4590;
url288=https://jira.local.com/rest/insight/1.0/objecttype/353/icon.png?size=288&uuid=708076cb-86b6-4d3e-8aae-0e3762cf4590; objectId=21408}
objectType : @{id=353; name=User Accounts; type=0; description=Object type for internal accounts needed for new platform onboarding.; icon=; position=12; created=2022-03-04T09:16:26.198Z; updated=2022-05-16T14:46:50.139Z; objectCount=0; objectSchemaId=8; inherited=False; abstractObjectType=False; parentObjectTypeInherited=False}
created : 2022-03-04T14:27:20.880Z
updated : 2022-06-21T15:05:45.509Z
hasAvatar : False
timestamp : 1655823945509
attributes : {@{id=165963; objectTypeAttribute=; objectTypeAttributeId=2537; objectAttributeValues=System.Object[]; objectId=21408}, @{id=165966; objectTypeAttribute=; objectTypeAttributeId=2538; objectAttributeValues=System.Object[]; objectId=21408}, @{id=165967; objectTypeAttribute=; objectTypeAttributeId=2539; objectAttributeValues=System.Object[];
objectId=21408}, @{id=165968; objectTypeAttribute=; objectTypeAttributeId=2550; objectAttributeValues=System.Object[]; objectId=21408}...}
extendedInfo : @{openIssuesExists=False; attachmentsExists=False}
_links : @{self=https://jira.local.com/secure/ShowObject.jspa?id=21408}
name : John Smith

And this is the attribute I want to update. Specifically I want to be able to change the searchValue and displayValue as required.

id     objectTypeAttributeId objectAttributeValues                                                                             objectId
-- --------------------- --------------------- --------
204243 2814 {@{user=; referencedType=False; searchValue=JIRAUSER10115; displayValue=John Smith (john.smith)}} 21408

This is the URL I'm using (if I run a GET request on it I get the correct attribute to modify):

$JiraInsightPUTURL = https://jira.local.com/rest/insight/1.0/objectattribute/204243

And the JSON I am sending:

$body = "{
"objectId": 21408,
"objectTypeAttributeId": 2814,
"objectAttributeValues": [{
"user": "",
"referencedType": "False",
"searchValue": "JIRAUSER10116",
"displayValue": "Joe Blogs (joe.blogs)"
}]
}"

And the header (I know this works fine):

$header = 
Name Value
---- -----
Authorization Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

The command I run:

$data = invoke-restmethod -uri $JiraInsightPUTURL -headers $header -body $body -method PUT

And the error returned:

invoke-restmethod : The remote server returned an error: (415).
At line:1 char:9
+ $data = invoke-restmethod -uri $JiraInsightPUTURL -headers $header -b ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

I have tried various ways of constructing the JSON, including making a variable and using the ConvertTo-JSON function, but they haven't helped, and I'm not certain that's were the error is. Any assistance/advice greatly appreciated.

1 answer

0 votes

I don't think we can modify SearchValue and DIsplayValue indenpendently.

From a java object and db entiry standpoint, there is no such attributes.

You can change the value of the attribute, and insight will calculate the searchValue and displayValue accordingly. 

 

In this case, you want to send a user object. Either with the user's key:

$body = "{
"objectId": 21408,
"objectTypeAttributeId": 2814,
"objectAttributeValues": [{
"user": {"key":"JIRAUSER10116"}
}]
}"

 Or with the user's name:

$body = "{
"objectId": 21408,
"objectTypeAttributeId": 2814,
"objectAttributeValues": [{
"user": {"name":"joe.blogs"}
}]
}"

Hi Peter-Dave, thanks for you're reply.  Alas, it hasn't worked.

I confirmed the JIRAUSER key was correct, by changing it manually to what I wanted, getting the code, and changing it back.

I tried both the User/Key and User/name variations, and I'm still getting the same 415.

$body = "{
  "objectId": 21408,
  "objectTypeAttributeId": 2814,
  "objectAttributeValues": [{
    "user": {"key":"JIRAUSER10116"}
  }]
}"

I also ensured all the quote marks were correctly escaped out (what I paste in here is the data sent to the server).

invoke-restmethod -uri $JiraInsightPUTURL -headers $header -body $body -method PUT
invoke-restmethod : The remote server returned an error: (415).
At line:1 char:1
+ invoke-restmethod -uri $JiraInsightPUTURL -headers $header -body $bod ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

I looked up the documentation (same one you posted) and figured out the correct format.

Try this:

$body = "{
  "objectId": 21408,
  "objectTypeAttributeId": 2814,
  "objectAttributeValues": [
    {"value":"JIRAUSER10116"}
  ]
}"

Still no joy, just the same 415 error, though I do see why you said to try that from the documentation.  When I look at the values for this attribute "value" isn't there, but perhaps it is swallowed by the backend and changed to the search and display values?

Matt

That's definitely the required format (at least with my version.... 8.10.1). I was able to do some test updates from Postman.

I don't have much experience with powershell, so I can't help debug that part.

But come to think, before I got the correct format, I never received a 415 (which normally stands for "unsupported media type").

So maybe try to add a Content-Type="application/json" header

Adding the new header has changed the message to a 500 - Internal Server Error, so I'm guessing it isn't that.

If it makes a difference we have Jira v8.15.0 and JIRA Service Management Application v4.15.0

Suggest an answer

Log in or Sign up to answer
TAGS

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