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

JMWE - callJira filter Edited

Hello.
I want to start using JMWE callJira() or callRest(). First case - I want to add another Option for my custom field - Select List (single choice) by API. I've used for that Build-your-own (scripted) Post-function in JMWE and my Nunjucks script is as following:

 

{{ "/rest/api/2/field/customfield_12800/context/14900/option" | callJira(verb = POST, body={
values:
{
"value": "xxxxxxxxxxxxxxx",
"disabled": false
}
})}}

Id of my customfield is 12800 and I have one context for that field - 14900 id.
I've used and checked GET method for that field to see that ID's are correct and it worked perfectly.

{{ "/rest/api/2/field/customfield_12800/context/14900/option" | callJira(verb = GET) | dump(2)}}

What is wrong with first Nunjucks script? When I'm trying to test that template I receive that (scrrenshot below) but nothing happened, field doesn't have a new option "xxxxxxxxxx".

Zrzut ekranu 2020-12-06 194202.png

1 answer

0 votes

Have you tried "dumping" the result of the call, to see what that returned object holds?

Also, my guess is that you need to pass an array of value objects, even when adding only one option. 

{{ "/rest/api/2/field/customfield_12800/context/14900/option" | callJira(verb = POST, body={
values:[
{
"value": "xxxxxxxxxxxxxxx",
"disabled": false
}
]})}}

Thank you @David Fischer _Innovalog_ for your time and answer :)

I've tried to dump that and I've received the same result as GET method - all options of that custom field.

Thank you for your tip with an array of objects but in that case result is the same.

I checked the REST API doc and the parameter is "options", not "values". Try this:

{{ "/rest/api/2/field/customfield_12800/context/14900/option" | callJira(verb = POST, body={
options:[
{
"value": "xxxxxxxxxxxxxxx",
"disabled": false
}
]})}}

Unfortunately, situation didn't change:

 

Zrzut ekranu 2020-12-08 211940.png

You mean the option wasn't added to the custom field's configuration scheme? Did you check the field configuration scheme (context) ID? Also, did you check the returned value (by "dumping" it)?

Yes, I meant that request doesn't work and option wasn't added.

ID's are proper because when I've changed above method on GET (with dump) I've received all actual options for context - ID 14900 from customfield - ID 12800.

{{ "/rest/api/2/field/customfield_12800/context/14900/option" | callJira(verb = GET)}}

When I use reqeuest as above (without dumping) I receive the same result like in POST method which doesn't work.

Zrzut ekranu 2020-12-09 200727.png

Again, for debugging purposes, always "dump(2)" the output to see what's inside the returned object.

Can you activate DEBUG-level logging on the JMWE Logs page and try again? This will log the actual call made out to Jira, which will help understand if the call is correct (based on the Jira REST API documentation). If it is correct, then I recommend you try the same call from Postman, to see if it works there. If it doesn't, you might need to ope a support request with Atlassian.

Like Mateusz likes this

I don't know what does it mean that part _needRefresh

Zrzut ekranu 2020-12-12 004352.png

But it's pretty interesting that log shows GET method in my POST request:

Zrzut ekranu 2020-12-12 004511.png

Dammit, you found the problem!

You are passing the verb parameter as:

callJira(verb = POST, ...

but that means that the verb will be the value of the POST variable - and since the POST variable is never set, it is empty (undefined). In that case, the default verb is used ("GET").

You need to pass a String as the verb:

callJira(verb = "POST", ...

Unfortunately, I didn't notice it in your previous posts. Sorry about that. 

Like Mateusz likes this

Thank you very much David, for your help and patience. It was really important case for me. Now I can start my adventure with API calls :)

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Software

Presenting the "Best of 2020" Jira Software roundup!

Catch up with Atlassian Product Managers in our 2020 Demo Den round-up! From Advanced Roadmaps to Code in Jira to Next-Gen Workflows, check out the videos below to help up-level your work in the new ...

7,105 views 8 28
Join discussion

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