grafl grafl - 2 months ago 10x
reST (reStructuredText) Question

Creating Sonatype Nexus repository using REST API causes HTTP/1.1 400 Bad Request

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.

According to the REST API documentation, available at


to create a new repository a POST request must look like this:

<?xml version="1.0" encoding="UTF-8"?>

So, my XML payload looks like this:

<?xml version="1.0" encoding="UTF-8"?>

and up to here (I hope) is OK.

I use cURL to POST this XML content:

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

The complete log of this command is this:

* Hostname was NOT found in DNS cache
* Trying
* Connected to localhost ( port 8081 (#0)
* Server auth using Basic with user 'admin'
> POST /nexus/service/local/repositories HTTP/1.1
> Authorization: Basic YWRtaW46YWRtaW4xMjM=
> User-Agent: curl/7.35.0
> Host: localhost:8081
> Accept: */*
> Content-Type:application/xml
> Content-Length: 327
* upload completely sent off: 327 out of 327 bytes
< HTTP/1.1 400 Bad Request
< Date: Mon, 20 Oct 2014 19:19:21 GMT
* Server Nexus/2.10.0-02 is not blacklisted
< Server: Nexus/2.10.0-02
< X-Frame-Options: SAMEORIGIN
< X-Content-Type-Options: nosniff
< Set-Cookie: rememberMe=deleteMe; Path=/nexus; Max-Age=0; Expires=Sun, 19-Oct-2014 19:19:21 GMT
< Content-Type: application/xml; charset=UTF-8
< Date: Mon, 20 Oct 2014 19:19:21 GMT
* Server Noelios-Restlet-Engine/1.1.6-SONATYPE-5348-V8 is not blacklisted
< Server: Noelios-Restlet-Engine/1.1.6-SONATYPE-5348-V8
< Content-Length: 183
<msg>No enum const class</msg>
* Connection #0 to host localhost left intact

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?


It looks like there may be a bug in the documentation, you also need to provide the "repoPolicy" element. Here's an example payload:


In general the best approach to use with Nexus and REST is to use the JSON payloads, these are easily discoverable because the UI calls through the REST layer and sends JSON. See here for more information: