Unable to build job with Rest API

I am trying to run a job from a rest API, but it fails with the below error. It works well from my local system but creates an issue when trying to run it from other sever -
Command I’m using:
curl -v --location --request POST ‘https://localhost.com/job/Restart/buildWithParameters?token=****’ --user username:token --form ‘ENVIRONMENT= “DEV”’ --form ‘SERVICE= “RESTART”’ --form ‘SERVER= “BOTH”’

HTTP/1.1 100 Continue
< HTTP/1.1 500 Server Error
< Cache-Control: no-cache,no-store,must-revalidate
< Content-Type: text/html;charset=utf-8
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Server: Jetty(9.4.43.v20210629)
< Set-Cookie: JSESSIONID.222ac32a=node0158y1h6h138l5om0vl3u9hdd022986.node0; Path=/; Secure; HttpOnly
< X-Content-Type-Options: nosniff
< X-Hudson-Theme: default
< Referrer-Policy: same-origin
< Cross-Origin-Opener-Policy: same-origin
< X-Hudson: 1.395
< X-Jenkins: 2.303.2
< X-Jenkins-Session: 6c5aaa22
< X-Frame-Options: sameorigin
< Date: Thu, 02 Dec 2021 13:41:06 GMT
< Content-Length: 6603

  • HTTP error before end of send, stop sending

Can someone suggest whats going wrong here.

We need more than “there was an error” Have you checked the system logs under configuration (or $JENKINS_HOME/logs on disk)? does it give yo any information?

Here is what I see in logs. But the parameters are defined well on Jenkins jobs. Also it works well from my local system, but not from my test server.
curl -v --location --request POST ‘https://localhost.com/job/Restart/buildWithParameters?token=****’ --user username:token --form ‘ENVIRONMENT= “DEV”’ --form ‘SERVICE= “RESTART”’ --form ‘SERVER= “BOTH”’
java.lang.IllegalArgumentException: Illegal choice for parameter ENVIRONMENT: “DEV”
at hudson.model.ChoiceParameterDefinition.checkValue(ChoiceParameterDefinition.java:163)
at hudson.model.ChoiceParameterDefinition.createValue(ChoiceParameterDefinition.java:170)
at hudson.model.ChoiceParameterDefinition.createValue(ChoiceParameterDefinition.java:29)
at hudson.model.SimpleParameterDefinition.createValue(SimpleParameterDefinition.java:39)
at hudson.model.ParametersDefinitionProperty.buildWithParameters(ParametersDefinitionProperty.java:183)
at jenkins.model.ParameterizedJobMixIn.doBuildWithParameters(ParameterizedJobMixIn.java:237)
at jenkins.model.ParameterizedJobMixIn$ParameterizedJob.doBuildWithParameters(ParameterizedJobMixIn.java:417)
at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:393)
at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:405)
at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:208)
at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:141)
at org.kohsuke.stapler.MetaClass$11.doDispatch(MetaClass.java:536)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:766)
Caused: javax.servlet.ServletException

are you using smart quotes or is that an artifact of discourse? I think jenkins is seeing literally space, smart quote, capital d, capital e, capital v, smart quote but I think you want just capital d, capital e, capital v

try --form=ENVIRONMENT=DEV or if you want to quote it, "--form=ENVIRONMENT=DEV"

Thanks, This fixed the issue.