unable to update custom field

Kenny Roostam April 23, 2023

Hello,

I am trying to create a ticket using rest api. One of the fields that I include in payload is customfield

"schema"{"type": "any","custom": "com.riadalabs.jira.plugins.insight:rlabs-customfield-default-object","customId": 19509}

When i check the json of this field in existing ticket it shows me this 

"customfield_19509"["Team123 (PTCI-1549)"]
So my json is

"customfield_19509" = @("Team123 (PTCI-1549)") | ConvertTo-Json
but i am getting this error 
{"errorMessages":[],"errors":{"customfield_19509":"expected Object"}} 
When i send the object it says data was not array, please help

2 answers

1 accepted

0 votes
Answer accepted
Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 23, 2023

Hi @Kenny Roostam and welcome to the community, 

The field you are trying to update is an asset field. As stated by your message, as well as gronthe asset rest api doc, the field should be an array. Please take a look at the documentation:

https://developer.atlassian.com/cloud/assetsapi/rest/api-group-assets/#api-group-assets

In addition, can you please paste here the request you are sending, as well as the payload?

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 23, 2023

@Kenny Roostam are on jira cloud or on premise?

Kenny Roostam April 23, 2023
Kenny Roostam April 23, 2023

@Alex Koxaras _Relational_ apologies, i was informed that its cloud but checking now, by going to /rest/api/2/serverInfo "deploymentType": "Server"  and version is v9.2

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 23, 2023

The check this link https://confluence.atlassian.com/servicemanagementserver/assets-rest-api-documentation-1044101761.html

Find the appropriate asset versions, as well as the right JSM version

Kenny Roostam April 23, 2023

Sorry @Alex Koxaras _Relational_ , so i can't set the values for assets fields using /rest/api/2/issue/ .I should use their own api right?

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 23, 2023

From the message you are getting, it seems that it works. However the data you are sending is not an object array.

Kenny Roostam April 23, 2023

I'm sending like this

$payLoad = @{
"fields" = @{
"customfield_19509" = @("Team123 (PTCI-1549)")
}} | ConvertTo-Json
but I get an error 
{"errorMessages":[],"errors":{"customfield_19509":"expected Object"}}

I'm sending like this
$payLoad = @{
"fields" = @{
"customfield_19509" = @(@{"value" = "Team123 (PTCI-1549)"})
}} | ConvertTo-Json

it creates the ticket however this field is not visible in ticket in browser. When i get the json of this ticket I see that its null "customfield_19509"null

However in another existing ticket json looks like this
"customfield_19509"["Team123 (PTCI-1549)"]
This ticket was created using UI
Do you know maybe how should I send this array properly?

Kenny Roostam April 23, 2023

I have tried with postman as well. When I send "customfield_19509"["Team123 (PTCI-1549)"
I get

 "errorMessages": [],
    "errors": {
        "customfield_19509""expected Object"
    }
and
When I send 
  "customfield_19509": [
      {
        "value""Team123  (PTCI-1549)"
      }
    ]
It goes thru and creates the ticket but customfield_19509: null and this field is not visible in ticket
0 votes
Kenny Roostam April 23, 2023

hi @Alex Koxaras _Relational_  thanks for quick response 

$token = ""
$headers = @{
Authorization = "Bearer $token"
"Content-Type" = "application/json"
}
$payLoad = @{
"fields" = @{
"project" = @{
"key" = "SDSD"
}
"issuetype" = @{
"name" = "Change Request"
}
"summary" = "Test change request"
"description" = "test change request"
"assignee" = @{
"name" = "john.doe"
}
"customfield_13804" = @{
"value" = "Standard"
}
"customfield_19509" = @("Team123 (PTCI-1549)")
}
} | ConvertTo-Json -Depth 10

Invoke-RestMethod -Uri https://jirainstanceXXX.com/rest/api/2/issue/ -Method 'Post' -Headers $headers -Body $payLoad -ErrorAction Stop

Suggest an answer

Log in or Sign up to answer