title: How to create pages in confluence using script runner
body: <p>All of the documentation I've found on ScriptRunner and creating pages in Confluence assumes you are doing it from Jira, so it adds unnecessary steps to authenticate. I want to run the script in Confluence with no input from Jira or outside system. </p>
  
  <p>Here is the code I had so far that gets hung up on the authenticatedRequestFactory:</p>
  
  <pre><code>import com.atlassian.applinks.api.ApplicationLink
  import com.atlassian.applinks.api.ApplicationLinkService
  import com.atlassian.applinks.api.application.confluence.ConfluenceApplicationType
  import com.atlassian.sal.api.component.ComponentLocator
  import com.atlassian.sal.api.net.Request
  import com.atlassian.sal.api.net.Response
  import com.atlassian.sal.api.net.ResponseException
  import com.atlassian.sal.api.net.ResponseHandler
  import groovy.json.JsonBuilder
  import groovy.json.JsonSlurper
  
  
  
  def confluenceLink = getPrimaryConfluenceLink()
  assert confluenceLink // must have a working app link set up
  
  def authenticatedRequestFactory = confluenceLink.createImpersonatingAuthenticatedRequestFactory()
  
  
  
  
  // set the page title - this should be unique in the space or page creation will fail
  def pageTitle = "Teset Discussion"
  def pageBody = """h3. Test
  
  {quote}This is a quote{quote}
  
  Yada yada, use this page to discuss the above...
  """
  
  def params = [
          type: "page",
          title: pageTitle,
          space: [
                  key: "COM" // set the space key - or calculate it from the project or something
          ],
          /* // if you want to specify create the page under another, do it like this:
           ancestors: [
               [
                   type: "page",
                   id: "14123220",
               ]
           ],*/
          body: [
                  storage: [
                          value: pageBody,
                          representation: "wiki"
                  ],
          ],
  ]
  
  
  authenticatedRequestFactory
          .createRequest(Request.MethodType.POST, "rest/api/content")
          .addHeader("Content-Type", "application/json")
          .setRequestBody(new JsonBuilder(params).toString())
          .execute(new ResponseHandler&lt;Response&gt;() {
      @Override
      void handle(Response response) throws ResponseException {
          if(response.statusCode != HttpURLConnection.HTTP_OK) {
              throw new Exception(response.getResponseBodyAsString())
          }
          else {
              def webUrl = new JsonSlurper().parseText(response.responseBodyAsString)["_links"]["webui"]
          }
      }
  })
  </code></pre>
  
  <p>The above sample is a trimmed down version from this documentation: <a href="https://scriptrunner.adaptavist.com/latest/jira/interacting-with-confluence-from-jira.html" rel="nofollow noreferrer">https://scriptrunner.adaptavist.com/latest/jira/interacting-with-confluence-from-jira.html</a> Appreciate any direction on how to just create a page. </p>