Unable to update the Multi Issue Picker field using Rest Api

I am trying to update a multi issue picker field in JIra using C# rest api. But the field is not getting updated and I am getting BadRequest error.

Also I got the following error message in the Log file


[c.a.j.bc.issue.DefaultIssueService] Exception occurred editing issue: java.lang.NullPointerException: Cannot get property 'id' on null object
java.lang.NullPointerException: Cannot get property 'id' on null object
	at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:60)
	at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:190)
	at org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:46)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:298)
	at com.onresolve.scriptrunner.canned.jira.fields.editable.issue.MultiIssuePickerField.convertTypeToDbValue(MultiIssuePickerField.groovy:84)
	at com.onresolve.scriptrunner.canned.jira.fields.editable.issue.MultiIssuePickerField.convertTypeToDbValue(MultiIssuePickerField.groovy)
	at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.convertTypesToDbObjects(AbstractMultiCFType.java:196)
	at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.createValue(AbstractMultiCFType.java:128)
	at com.onresolve.scriptrunner.canned.jira.fields.editable.AbstractTrackedMultiCFType.super$3$createValue(AbstractTrackedMultiCFType.groovy)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:101)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1217)
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:144)
	at com.onresolve.scriptrunner.canned.jira.fields.editable.AbstractTrackedMultiCFType.createValue(AbstractTrackedMultiCFType.groovy:30)
	at com.onresolve.scriptrunner.canned.jira.fields.editable.AbstractTrackedMultiCFType.createValue(AbstractTrackedMultiCFType.groovy)
	at com.atlassian.jira.issue.fields.ImmutableCustomField.createValue(ImmutableCustomField.java:701)
	at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:414)
	at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:400)
	at com.atlassian.jira.issue.fields.OrderableField$updateValue$5.call(Unknown Source)
	at com.onresolve.scriptrunner.runner.field.IssueParametersCapturingImmutableCustomField.updateValue(IssueParametersCapturingImmutableCustomField.groovy:34)
	at com.atlassian.jira.issue.managers.DefaultIssueManager.updateFieldValues(DefaultIssueManager.java:716)
	at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:667)
	at com.atlassian.jira.issue.managers.RequestCachingIssueManager.updateIssue(RequestCachingIssueManager.java:222)
	at com.atlassian.jira.bc.issue.DefaultIssueService.update(DefaultIssueService.java:351)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at com.atlassian.plugin.util.ContextClassLoaderSettingInvocationHandler.invoke(ContextClassLoaderSettingInvocationHandler.java:26)
	at com.sun.proxy.$Proxy532.update(Unknown Source)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
	at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:56)
	at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:60)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:137)
	at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java:70)
	at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:53)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.eclipse.gemini.blueprint.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:57)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:137)
	at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
	at com.sun.proxy.$Proxy2948.update(Unknown Source)
	at com.atlassian.jira.rest.v2.issue.UpdateIssueResource.editIssue(UpdateIssueResource.java:70)
	at com.atlassian.jira.rest.v2.issue.IssueResource.editIssue(IssueResource.java:943)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	... 5 filtered
	at com.atlassian.jira.rest.exception.ExceptionInterceptor.intercept(ExceptionInterceptor.java:55)
	... 1 filtered
	at com.atlassian.jira.rest.v2.issue.scope.RequestScopeInterceptor.intercept(RequestScopeInterceptor.java:39)
	... 15 filtered
	at com.atlassian.plugins.rest.module.RestDelegatingServletFilter$JerseyOsgiServletContainer.doFilter(RestDelegatingServletFilter.java:160)
	... 1 filtered
	at com.atlassian.plugins.rest.module.RestDelegatingServletFilter.doFilter(RestDelegatingServletFilter.java:70)
	... 36 filtered
	at com.atlassian.jira.plugin.mobile.web.filter.MobileAppRequestFilter.doFilter(MobileAppRequestFilter.java:59)
	... 4 filtered
	at com.atlassian.jira.plugin.mobile.login.MobileLoginSuccessFilter.doFilter(MobileLoginSuccessFilter.java:54)
	... 3 filtered
	at com.atlassian.diagnostics.internal.platform.monitor.http.HttpRequestMonitoringFilter.doFilter(HttpRequestMonitoringFilter.java:55)
	... 8 filtered
	at com.atlassian.web.servlet.plugin.request.RedirectInterceptingFilter.doFilter(RedirectInterceptingFilter.java:21)
	... 43 filtered
	at com.atlassian.ratelimiting.internal.filter.RateLimitFilter.doFilter(RateLimitFilter.java:73)
	... 3 filtered
	at com.atlassian.troubleshooting.thready.filter.AbstractThreadNamingFilter.doFilter(AbstractThreadNamingFilter.java:46)
	... 17 filtered
	at com.atlassian.jira.security.JiraSecurityFilter.lambda$doFilter$0(JiraSecurityFilter.java:66)
	... 1 filtered
	at com.atlassian.jira.security.JiraSecurityFilter.doFilter(JiraSecurityFilter.java:64)
	... 16 filtered
	at com.atlassian.plugins.rest.module.servlet.RestSeraphFilter.doFilter(RestSeraphFilter.java:38)
	... 3 filtered
	at com.atlassian.pats.web.filter.TokenBasedAuthenticationFilter.doFilter(TokenBasedAuthenticationFilter.java:82)
	... 19 filtered
	at com.atlassian.jira.servermetrics.CorrelationIdPopulatorFilter.doFilter(CorrelationIdPopulatorFilter.java:30)
	... 5 filtered
	at com.atlassian.plugins.authentication.basicauth.filter.DisableBasicAuthFilter.doFilter(DisableBasicAuthFilter.java:70)
	... 8 filtered
	at com.atlassian.ratelimiting.internal.filter.RateLimitPreAuthFilter.doFilter(RateLimitPreAuthFilter.java:71)
	... 3 filtered
	at com.atlassian.web.servlet.plugin.request.RedirectInterceptingFilter.doFilter(RedirectInterceptingFilter.java:21)
	... 4 filtered
	at com.atlassian.troubleshooting.thready.filter.AbstractThreadNamingFilter.doFilter(AbstractThreadNamingFilter.java:46)
	... 3 filtered
	at com.atlassian.web.servlet.plugin.LocationCleanerFilter.doFilter(LocationCleanerFilter.java:36)
	... 7 filtered
	at com.wombatscorp.jira.tokens.filters.TokenFilter.doFilter(TokenFilter.java:147)
	... 22 filtered
	at com.atlassian.jira.servermetrics.MetricsCollectorFilter.doFilter(MetricsCollectorFilter.java:25)
	... 25 filtered`Preformatted text`
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

My code is as below


public void UpdateDesignReference(ConfigParams configParams,Issue issue, string customField, string designIds)
        {
            try
            {
                string[] designs = designIds.Split(',');
                string add_value = null;
                for (int i = 0; i < designs.Count(); i++)
                {
                    if (i == 0)
                    {
                        add_value = "{\"add\":\""+ designs[i] + "\"}";
                    }
                    else
                    {
                        add_value = add_value + ",{\"add\":\"" + designs[i] + "}";
                    }

                }
                string requestUrl = configParams.JIraUrl+ "/rest/api/latest/issue/"+ issue.Key;
                string m_EncodedCredential = Jsonparse.Text_Base64Encode(configParams.JiraUserid + ":" + configParams.JiraPassword);

                var json_str = @"{    ""update"": {""" + customField + @""": [" + add_value + "]    }}";

                var client = new RestClient(requestUrl);
                client.Timeout = -1;
                var request = new RestRequest(Method.PUT);
                request.Parameters.Clear();
                request.AddHeader("Authorization", "Basic " + m_EncodedCredential);
                request.AddHeader("Content-Type", "application/json");              
                request.RequestFormat = DataFormat.Json;
                request.AddParameter("application/json", json_str, ParameterType.RequestBody);
                IRestResponse response = client.Execute(request);
                
            }
            catch(Exception ex)
            {
                Logger.Instance.ErrorLog("Exception in updating design References " + ex.Message);
                Logger.Instance.ErrorLog("Exception in updating design References " + ex.InnerException);
                Logger.Instance.ErrorLog("Exception in updating design References " + ex.StackTrace);
            }
        }

Hi @RatheeshRajavel. I don’t have a dev environment with C# to stage your code. That being said, in your UpdateDesignReference method, when you form your requestUrl, could there be a typo in the reference to the Jira base URL? It’s the only variable that’s not camelCased properly (configParams.JIraUrl).

hi @nmansilla

We have checked the configParams.JIraUrl variable. And the variable value is shown properly.

We used the Postman for updating the field and it is working fine… But when we tried the code in C# it is not working.

This is the code generated from the Postman

var client = new RestClient(“https://htl-jira-dev22.merge.com/rest/api/latest/issue/HEMO-34332”);
var request = new RestRequest(Method.PUT);
request.AddHeader(“Postman-Token”, “58b04787-4ba3-4eb2-99e3-c7409b9394f0”);
request.AddHeader(“cache-control”, “no-cache”);
request.AddHeader(“Content-Type”, “application/json”);
request.AddParameter(“undefined”, “{\n "update": {\n "customfield_15518": [\n {\n "remove": "HEMO-30006"\n },\n {\n "remove": "HEMO-30005"\n }\n ]\n }\n}”, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

We modified the above code to use it in C#.