title: Creating Sonatype Nexus repository using REST API causes HTTP/1.1 400 Bad Request
body: <p>In my attempt to create a new Sonatype Nexus hosted repository, using the REST API, I get an "HTTP/1.1 400 Bad Request". I am using a Sonatype Nexus™ 2.10.0-02, running locally.</p>
  
  <p>According to the REST API documentation, available at</p>
  
  <pre><code>http://localhost:8081/nexus/nexus-restlet1x-plugin/default/docs/path__repositories.html
  </code></pre>
  
  <p>to create a new repository a POST request must look like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;repository&gt;
      &lt;data&gt;
         &lt;format&gt;...&lt;/format&gt;
         &lt;providerRole&gt;...&lt;/providerRole&gt;
         &lt;exposed&gt;...&lt;/exposed&gt;
         &lt;id&gt;...&lt;/id&gt;
         &lt;name&gt;...&lt;/name&gt;
         &lt;contentResourceURI&gt;...&lt;/contentResourceURI&gt;
         &lt;repoType&gt;...&lt;/repoType&gt;
         &lt;provider&gt;...&lt;/provider&gt;
      &lt;/data&gt;
  &lt;/repository&gt;
  </code></pre>
  
  <p>So, my XML payload looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;repository&gt;
      &lt;data&gt;
          &lt;format&gt;maven2&lt;/format&gt;
          &lt;providerRole&gt;org.sonatype.nexus.proxy.repository.Repository&lt;/providerRole&gt;
          &lt;exposed&gt;true&lt;/exposed&gt;
          &lt;id&gt;my-releases&lt;/id&gt;
          &lt;name&gt;MyReleases&lt;/name&gt;
          &lt;contentResourceURI&gt;http://localhost:8081/nexus/content/repositories/my-releases&lt;/contentResourceURI&gt;
          &lt;repoType&gt;hosted&lt;/repoType&gt;
          &lt;provider&gt;maven2&lt;/provider&gt;
      &lt;/data&gt;
  &lt;/repository&gt;
  </code></pre>
  
  <p>and up to here (I hope) is OK.</p>
  
  <p>I use cURL to POST this XML content:</p>
  
  <pre><code>curl -i -H "Accept: application/xml" -H "Content-Type: application/xml" -f -X POST -v -d "@$(pwd)/insert_oss_repository.xml" -u admin:admin123 http://localhost:8081/service/local/repositories
  </code></pre>
  
  <p>The complete log of this command is this:</p>
  
  <pre><code>* Hostname was NOT found in DNS cache
  *   Trying 127.0.0.1...
  * Connected to localhost (127.0.0.1) port 8081 (#0)
  * Server auth using Basic with user 'admin'
  &gt; POST /nexus/service/local/repositories HTTP/1.1
  &gt; Authorization: Basic YWRtaW46YWRtaW4xMjM=
  &gt; User-Agent: curl/7.35.0
  &gt; Host: localhost:8081
  &gt; Accept: */*
  &gt; Content-Type:application/xml
  &gt; Content-Length: 327
  &gt; 
  * upload completely sent off: 327 out of 327 bytes
  &lt; HTTP/1.1 400 Bad Request
  &lt; Date: Mon, 20 Oct 2014 19:19:21 GMT
  * Server Nexus/2.10.0-02 is not blacklisted
  &lt; Server: Nexus/2.10.0-02
  &lt; X-Frame-Options: SAMEORIGIN
  &lt; X-Content-Type-Options: nosniff
  &lt; Set-Cookie: rememberMe=deleteMe; Path=/nexus; Max-Age=0; Expires=Sun, 19-Oct-2014 19:19:21 GMT
  &lt; Content-Type: application/xml; charset=UTF-8
  &lt; Date: Mon, 20 Oct 2014 19:19:21 GMT
  * Server Noelios-Restlet-Engine/1.1.6-SONATYPE-5348-V8 is not blacklisted
  &lt; Server: Noelios-Restlet-Engine/1.1.6-SONATYPE-5348-V8
  &lt; Content-Length: 183
  &lt; 
  &lt;nexus-error&gt;
    &lt;errors&gt;
      &lt;error&gt;
        &lt;id&gt;*&lt;/id&gt;
        &lt;msg&gt;No enum const class org.sonatype.nexus.proxy.maven.RepositoryPolicy.null&lt;/msg&gt;
      &lt;/error&gt;
    &lt;/errors&gt;
  * Connection #0 to host localhost left intact
  &lt;/nexus-error&gt;
  </code></pre>
  
  <p>First of all, I would read your comment regarding the XML payload of my POST request. Second, if they took the time to create a sort of documentation, why don't they provide also a working example? Third, if they made this REST API available why don't they respond with a human readable answer?</p>