title: How to POST JSON data in body with Jenkins http-request plugin and Pipeline?
body: <p>With v1.8.10 of the http-request plugin for Jenkins (I'm running 1.643), there is now support for POSTing a body in the request -- so this <a href="https://stackoverflow.com/questions/36082421/where-body-is-put-in-post-with-http-request-plugin-in-jenkins">thread</a> does not apply. I am wondering how to use this functionality in a Pipeline (v2.1) Groovy script? The Snippet Generator does not include this new field, so I have no example to build off of.</p>
  
  <p><a href="https://i.stack.imgur.com/tQOIL.png" rel="noreferrer"><img src="https://i.stack.imgur.com/tQOIL.png" alt="Snippet Generator"></a> </p>
  
  <p>I have tried various ways to get the JSON data into the request body, but my Tomcat server always returns http 400 status code: <code>The request sent by the client was syntactically incorrect.</code></p>
  
  <p>Things I have tried:</p>
  
  <pre><code>def toJson = {
      input -&gt;
      groovy.json.JsonOutput.toJson(input)
  }
  def body = [
      displayName: [
          text: "smoke test"],
      description: [
          text: "for smoke testing"],
      genusTypeId: "type"
  ]
  response = httpRequest consoleLogResponseBody: true, contentType: 'APPLICATION_JSON', httpMode: 'POST', requestBody: toJson(body), url: "https://${host}", validResponseCodes: '200'
  </code></pre>
  
  <hr>
  
  <pre><code>def body = [
      displayName: [
          text: "smoke test"],
      description: [
          text: "for smoke testing"],
      genusTypeId: "type"
  ]
  response = httpRequest consoleLogResponseBody: true, contentType: 'APPLICATION_JSON', httpMode: 'POST', requestBody: body, url: "https://${host}", validResponseCodes: '200'
  </code></pre>
  
  <hr>
  
  <pre><code>response = httpRequest consoleLogResponseBody: true, contentType: 'APPLICATION_JSON', httpMode: 'POST', requestBody: "{\"displayName\":{\"text\":"smoke test\"},\"description\":{\"text\":\"for smoke testing\"}, \"genusTypeId\":\"type\"}", url: "https://${host}", validResponseCodes: '200'
  </code></pre>
  
  <hr>
  
  <pre><code>response = httpRequest consoleLogResponseBody: true, contentType: 'APPLICATION_JSON', httpMode: 'POST', requestBody: "'{\"displayName\":{\"text\":"smoke test\"},\"description\":{\"text\":\"for smoke testing\"}, \"genusTypeId\":\"type\"'}", url: "https://${host}", validResponseCodes: '200'
  </code></pre>
  
  <p>Scanning the <code>http-request</code> library code, it seems like setting this flag should work. I don't know how Pipeline plugins / Jenkins plugins work, so I wonder if the Pipeline -> http-request code accounts for this new parameter? Can someone point me to how I can make POSTs with request bodies work with the Pipeline, or where I need to modify Pipline plugin code to make the connection?</p>