I am trying to trigger a Jenkins build job using Microsoft Power Automate. The build job works when I use the buildWithParameters endpoint, and use the following:
Method: POST
URL: https://[Jenkins Instance URL]/[Job Path]/buildWithParameters?
However, I need to pass in user values into the build job which requires passing in a JSON body of name:value pairs to the request.
When using curl, the following works:
curl -k -X POST -u "serviceuser" https://[Jenkins Instance URL]/[Job Path]/build --form json='{"parameter":[{"name":"FIELD_NAME", "value":"Value to insert"}]}
However, if I try the same in Power Automate using JSON (which looks like this using a curl to JSON converter):
{
"data": {
"json": "{\"parameter\":[{\"name\":\"FIELD_NAME\", \"value\":\"Value to insert\"}]}"
}
}
I get an error stating:
{
"error": {
"code": 400,
"source": "flow-apim-xxxx-002-xxxx-01.azure-apim.net",
"clientRequestId": "22e2f3fa-dfe6-4b27-b5f9-9f425b61250a",
"message": "The response is not in a JSON format.",
"innerError": "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>\n<title>Error 400 Nothing is submitted</title>\n</head>\n<body><h2>HTTP ERROR 400 Nothing is submitted</h2>\n<table>\n<tr><th>URI:</th><td>[Job Path]/build</td></tr>\n<tr><th>STATUS:</th><td>400</td></tr>\n<tr><th>MESSAGE:</th><td>Nothing is submitted</td></tr>\n<tr><th>SERVLET:</th><td>Stapler</td></tr>\n</table>\n<hr><a href=\"https://eclipse.org/jetty\">Powered by Jetty:// 9.4.41.v20210516</a><hr/>\n\n</body>\n</html>\n"
}
}
My question is how do I take the above curl command which successfully triggers the job and passes in the values in the --form parameter and convert that into a REST API call with JSON?
Any help would be greatly appreciated as by all accounts, this should be possible but I believe it's the format of the API call which is not correct. The Jenkins reference material doesn't offer much help: https://www.jenkins.io/doc/book/using/remote-access-api/
The Body of your request is indeed not valid JSON. Try sending: