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

Jira API - Insight object customfield

Gleb Kartashov January 20, 2020

Hi!

I'm using REST API to create issues in Jira. However, I was not able to fill a "Insight object" custom field. I'm getting "data was not an array" and "expected Object" error when passing values to these fields:

image.png

The code:

request.post(myhost.com, {
'auth': {
'user': 'user',
'pass': 'pass',
'sendImmediately': true
},
json: {
fields: {
project : {
key : "test"
},
summary: createDescription[i],
description : createInformation[i],
customfield_12300 : createNumber[i],
customfield_10218 : "SERVICE-61413",
customfield_10225 : "SERVICE-61481",
customfield_10226 : "SERVICE-61574",
issuetype : {
name: "test"
}
}
}
}

 I was trying to fix "data was not an array" error by passing values as

customfield_10218 : ["SERVICE-61413"],
customfield_10225 : ["SERVICE-61481"],
customfield_10226 : ["SERVICE-61574"],

but this resulted in "expected Object" error:

image.png

Also I've tried to pass these values not as object key but object name, but this didn't work either.

How do I pass values to Insight object customfield correctly?

4 answers

2 accepted

10 votes
Answer accepted
Nader Nassif
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 22, 2020

Hi Gleb,

We will paste the answer here for everyone to benefit from the information ;)

The correct format to send in the JSON payload would be

"customfield_10225" : [{"key" : "SERVICE-1"}]

Cheers!

Nader

Mindville team

Lenin Raj
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 22, 2020

Glad it was sorted. It will be useful for others, definitely.

djenkins
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 10, 2020

SOLVED: Read my response below for the Cloud solution.


@Nader Nassif Is this the same for Cloud? I'm having trouble sending custom fields through the JSD API using this format. Here is part of the JSD data used. 

"serviceDeskId": "194",
"requestTypeId": "568",
"requestFieldValues": {
"summary": "Cloud JSD API with custom Insight field",
"description": "Cloud JSD API new request custom Insight field",
"customfield_12675": [{"key":"AST-133"}]
}

 I'm curious to know whether this works for Cloud, and if we can use the JSD API to use the custom fields in insight. This API successfully creates a new issue, but does not include the custom Insight field. 

Like # people like this
Ricky LaFleur March 4, 2021

Hi @Nader Nassif ,

 

thanks for your reply.  If I use key number, this works, however, when I use object attribute name it newly created issue remains empty. How can we use name instead of keys?

 

Thanks! 

4 votes
Answer accepted
djenkins
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 10, 2020

After spending a bunch of time playing with the API this is how I got everything to work for Cloud which is different than the Server explanation in my use case. 

Using JSD Cloud API for the request and this is the format that works for Cloud instances using custom fields with Insight. 

"customfield_12675" : [{"value":"com.riadalabs.jira.plugins.insight/2202_85"}]

This worked for me on Cloud however, I think the abovementioned solution is still valid for Server/DC. 

daniel_szewczyk March 22, 2022

Hello,

How can one get the ID of the object for the value (in your case assuming this is "2202_85")?

Thank you in advance!

Regards,

Daniel

Derek White September 16, 2022

The current format seems to be:

"customfield_10xxx": [{"id":"<workspaceId>:<objectId>"}]

All 3 ids can be seen using /rest/api/3/browse/<issueKey>?expand=all on an issue that has the field(s) already set.

E.G.

    "customfield_10xxx": [
      {
        "workspaceId": "1-2-3-a-b",
        "id": "1-2-3-a-b:1",
        "objectId": "1"
      }
    ]

These are also returned when creating an object or searching for objects using the Insight API, although they reference them by different names:

{
"workspaceId": "1-2-3-a-b",
"globalId": "1-2-3-a-b:1",
"id": "1",
...
}

Would be nice if there was consistency.

And, documentation, like Server/DC has: https://confluence.atlassian.com/insightapps/insight-with-jira-rest-api-1085180905.html

Like # people like this
0 votes
Ricky LaFleur March 4, 2021

-

0 votes
Lenin Raj
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 21, 2020

Hi @Gleb Kartashov 

What is the type of "Insight" custom object? 

One trick is to set this value via UI manually for one Issue and retrieve it via "Get Issue" and see what format the value comes back as. Then you can use the same format to send back for new issues.

Gleb Kartashov January 21, 2020

Thanks for responding! I've tried to create a test issue and get it from API, this is what Insight objects look like:

image.pngTried to pass this exact values to create issue script but still got "expected Object" error

Gleb Kartashov January 21, 2020

So did some experiments with JS code and turned out this format

customfield_10218 : [{0:"SERVICE-1"}]

makes it possible to create an issue. But in Jira this field is empty and if I try to get newly created issues from API the fields are empty also.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events