Unable to create custom field or update using REST API in jira cloud APP

Hi,
I am unable to create custom field or update.
Please help

I am trying to create a jira cloud app where user can add options to custom field(list type).

using atlassian connect i am able get all custom fields as below

AP.request(’/rest/api/3/field’, {
success: function(responseText){});

but I am unable to create or update those custom fields
trying to create any custom field as below but no luck.

AP.request({
url: ‘/rest/api/3/field’,
type: ‘POST’,
data: {
searcherKey: “com.atlassian.jira.plugin.system.customfieldtypes:grouppickersearcher”,
name: ‘New custom field’,
type: “com.atlassian.jira.plugin.system.customfieldtypes:grouppicker”,
description: ‘test’},
success: function(responseText){}

thanks,
Nitish

@nvulli did you set the permission scope in your descriptor correctly? In order to create custom fields you need the ‘ADMIN’ permission declared.

1 Like

hi @biro,
Thanks for the response .
Can you please share the sample permission scope. if possible create and fields list options
I tried below values.
I am able to create filed with installation but not with api.

"lifecycle": {
    "installed": "/installed"
},
"scopes": [
     "READ", "WRITE" 
],

"modules": {
    "jiraIssueFields": [
        {
            "key" : "team-issue-field",
            "name" : {
                "value" : "Team"
            },
            "description" : {
                "value" : "Team tied to issue"
            },
            "type": "single_select",
            "extractions": [{
                "path": "category",
                "type": "string",
                "name": "category"
            }]}
    ],

After adding ADMIN scope response code changed to 415
can you please check the request data

“scopes”: [
“READ”, “WRITE”,“ADMIN”
],

AP.request({
url: ‘/rest/api/3/field/’,
type: ‘POST’,
data: {
searcherKey: “com.atlassian.jira.plugin.system.customfieldtypes:grouppickersearcher”,
name: ‘New custom field’,
type: “com.atlassian.jira.plugin.system.customfieldtypes:grouppicker”,
description: ‘test’},
success: function(responseText){

“scopes”: [
“READ”, “WRITE”,“ADMIN”
],

This is the correct scope declaration so you should be fine for permissions. Error 415 usually means Unsuported Media Type which can be caused by not setting the contentType which should be application/json

Hi @biro,

even after adding contentType i am getting same error:
can you please help with any one of the requests or please share some working example

. create custom field

AP.request({
    url: '/rest/api/3/field/',
    type: 'POST',
    'Content-Type': 'application/json',
 
    data: { 
        searcherKey: "com.atlassian.jira.plugin.system.customfieldtypes:grouppickersearcher",
        name: "New_custom_field",
        description: "Custom field for picking groups",
        type: "com.atlassian.jira.plugin.system.customfieldtypes:grouppicker"
    }, success: function(responseText){})

adding option to already created custom filed while installing APP
 AP.request({
    url: '/rest/api/3/field/my-app__team-issue-field/option',
    type: 'POST',
    'Content-Type': 'application/json',
    data: [ "Team1","Team2"],
    success: function(responseText){})

created custom field using below conf

"jiraIssueFields": [
            {
                "key" : "team-issue-field",
                "name" : {
                    "value" : "APP_custom_Field-select"
                },
                "description" : {
                    "value" : "APP_custom_Field issue"
                },
                "custom":true,
                "orderable":true,
                "navigable":true,
                "searchable":true,
                "type": "single_select",
                "schema":{"type":"option","custom":"com.atlassian.jira.plugin.system.customfieldtypes:select"},
                "extractions": [{
                    "path": "category",
                    "type": "string",
                    "name": "category"
                }]}
        ],

thanks,
Nitish

Finally able to create custom field option with.

  AP.request({
    url: '/rest/api/2/field/my-app__team-issue-field/option',
    type: 'POST',
  
     contentType: "application/json",

    data: '{"value": "parent", "child": {"value":"child"} }',
    success: function(responseText){

still custom_field failing

@nvulli we use ACE and trigger API requests using httpClient from the context. Not super familiar with the Javascript API. Do you get any error message?

Hi @biro,

i am able to create custom_fields in 2 ways .

  1. by including “jiraIssueFields” module in atlassian-connect.json
    2)using below rest-api
    /rest/api/3/field/

with 1st option i am able add/view options with API and field is locked (will be removed if we uninstall APP)

with 2nd option I am unable to add/view option using API and getting below error
https://vunitish.atlassian.net/rest/api/3/field/customfield_10113/option

{"errorMessages":[],"errors":{"fieldKey":"Field key 'customfield_10113' is not valid"}}"

how can we add/view option on custom_field created using second option ??

if possible can your share your sample of "ACE and trigger API requests using httpClient with context "

Thanks,
Nitish

@nvulli could you post the exact code here for creating custom field + adding options script

hi @biro

I just created using “atlas-connect new -t jira jira-activity” and then made changes to below 2 files.
Note: I am only able to create app specific field by including field module in “atlassian-connect.json”

atlassian-connect.json
public/js/jira-activity.js

adding these 2 files content

atlassian-connect.json

{
    "key": "my-app",
    "name": "My app",
    "description": "My very first app",
    "vendor": {
        "name": "Atlassian Developers",
        "url": "https://developer.atlassian.com/"
	},
    "baseUrl": "{{localBaseUrl}}",
    "links": {
        "self": "{{localBaseUrl}}/atlassian-connect.json",
        "homepage": "{{localBaseUrl}}/atlassian-connect.json"
    },
    "authentication": {
        "type": "jwt"
    },
    "lifecycle": {
        "installed": "/installed"
    },
    "scopes": [
         "READ", "WRITE","ADMIN"
    ],
   
    "modules": {
        "jiraIssueFields": [
            {
                "key" : "team-issue-field-2",
                "name" : {
                    "value" : "APP_custom_Field-select-2"
                },
                "description" : {
                    "value" : "APP_custom_Field issue"
                },
                "custom":true,
                "orderable":true,
                "navigable":true,
                "searchable":true,
                "type": "single_select",
                "schema":{"type":"option","custom":"com.atlassian.jira.plugin.system.customfieldtypes:select"},
                "extractions": [{
                    "path": "category",
                    "type": "string",
                    "name": "category"
                }]}
        ],

        "generalPages": [
    {
        "key": "activity",
        "location": "system.top.navigation.bar",
        "name": {
            "value": "Activity"
        },
        "url": "/activity",
        "conditions": [{
            "condition": "user_is_logged_in"
        }]
    }
  
]
    },
    "apiMigrations": {
        "gdpr": true
    }
}

public/js/jira-activity.js

//APP specific   field able to add option
  AP.request({
    url: '/rest/api/2/field/my-app__team-issue-field/option',
    type: 'POST',
  
     contentType: "application/json",

    //data: '{"value": "parent", "child": {"value":"child"} }',
    data: '{"value": "parent" }',
    success: function(responseText){
      console.log(responseText);
    },
    beforeSend: function (xhr) {
        xhr.setRequestHeader ("Authorization", "Basic " + btoa(" XXX : XXX "));
        },
    error: function(xhr, statusText, errorThrown){
      console.log(arguments);
    }
  });

/// working field creation  , created field is not app specific
AP.request({
    url: '/rest/api/3/field/',
    type: 'POST',
    
    contentType: "application/json",
    
 
    data: '{ "searcherKey": "com.atlassian.jira.plugin.system.customfieldtypes:grouppickersearcher", "name": "Custom_Rest", "description": "Custom field for picking groups", "type": "com.atlassian.jira.plugin.system.customfieldtypes:grouppicker"  }',
    success: function(responseText){
      console.log(responseText);
    },
    beforeSend: function (xhr) {
        xhr.setRequestHeader ("Authorization", "Basic " + btoa(" XXXX : XXXXX "));
        },
    error: function(xhr, statusText, errorThrown){
      console.log(arguments);
    }
  });