title: Uploading a template in apache NiFi using Rest API in Java
body: <p>I am trying to create a REST API call to import a template into my NiFi UI post which Instantiate the same. </p>
  
  <p>Below is the code which I tried,</p>
  
  <pre><code>String siteUrl = "localhost";
  String portNumber = "8080";
  String pId = "f80896d4-c71f-3395-d527-8c6bd69f44d0";
  String pathname = "D:\\Users\\bramasam\\Downloads\\BalaBackUp.xml";
  String restString = "http://" + siteUrl + ":" + portNumber + "/nifi-api/process-groups/" + pId + "/templates/upload";
  HttpPost httpPost = new HttpPost(restString);
  
  File fileObj = new File(pathname);
  
  httpPost.addHeader("Content-type", "multipart/form-data");
  
  FileEntity fileEntity = new FileEntity(fileObj, ContentType.MULTIPART_FORM_DATA);
  
  httpPost.setEntity(fileEntity);
  
  HttpClient httpClient = HttpClientBuilder.create().build();
  HttpResponse response = httpClient.execute(httpPost);
  StatusLine status = response.getStatusLine();
  System.out.println(status.getStatusCode());
  </code></pre>
  
  <p>Below is the {id} from the BalaBackUp.xml file which I am trying to import from</p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;template encoding-version="1.1"&gt;
    &lt;description&gt;&lt;/description&gt;
    &lt;groupId&gt;bd5dba8b-015d-1000-1fd5-450ede38b7a5&lt;/groupId&gt;
    &lt;name&gt;BalaBackUp&lt;/name&gt;
    &lt;snippet&gt;
      &lt;processGroups&gt;
        &lt;id&gt;f80896d4-c71f-3395-0000-000000000000&lt;/id&gt;
        &lt;parentGroupId&gt;29a5776d-9728-3fee-0000-000000000000&lt;/parentGroupId&gt;
        &lt;position&gt;
          &lt;x&gt;0.0&lt;/x&gt;
          &lt;y&gt;0.0&lt;/y&gt;
        &lt;/position&gt;
        &lt;comments&gt;&lt;/comments&gt;
        &lt;contents&gt;
          &lt;connections&gt;
            &lt;id&gt;c0d0e26d-5ee2-3d60-0000-000000000000&lt;/id&gt;
            &lt;parentGroupId&gt;f80896d4-c71f-3395-0000-000000000000&lt;/parentGroupId&gt;
            &lt;backPressureDataSizeThreshold&gt;1 GB&lt;/backPressureDataSizeThreshold&gt;
            &lt;backPressureObjectThreshold&gt;10000&lt;/backPressureObjectThreshold&gt;
            &lt;destination&gt;
              &lt;groupId&gt;f80896d4-c71f-3395-0000-000000000000&lt;/groupId&gt;
              &lt;id&gt;1f9e926a-71fc-356f-0000-000000000000&lt;/id&gt;
              &lt;type&gt;PROCESSOR&lt;/type&gt;
  </code></pre>
  
  <p>I am getting a response code of 500 and with the below response</p>
  
  <pre><code>HttpResponseProxy{HTTP/1.1 500 Internal Server Error [Date: Thu, 28 Sep 2017 09:43:28 GMT, X-Frame-Options: SAMEORIGIN, Content-Type: text/plain, Transfer-Encoding: chunked, Server: Jetty(9.4.3.v20170317)] ResponseEntityProxy{[Content-Type: text/plain,Chunked: true]}}
  </code></pre>
  
  <p>can you please help me on what I am missing?</p>