JMWE - callJira filter

Mateusz December 6, 2020

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

1 accepted

0 votes
Answer accepted
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 6, 2020

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

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 6, 2020

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
}
]})}}
Mateusz December 7, 2020

Thank you @David Fischer 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.

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 7, 2020

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
}
]})}}
Mateusz December 8, 2020

Unfortunately, situation didn't change:

 

Zrzut ekranu 2020-12-08 211940.png

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 8, 2020

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)?

Mateusz December 9, 2020

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

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 9, 2020

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
Mateusz December 11, 2020

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

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 11, 2020

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
Mateusz December 11, 2020

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
AUG Leaders

Atlassian Community Events