discogs post https://api.discogs.com/marketplace/listings? returned a response status of 422 null

78 views Asked by At

I'm trying to post api.discogs.com/marketplace/listings?... in java.

When I try to make a newlisting post, the result is "returned a response status of 422 null".

"422 Unprocessable Entity Your request was well-formed, but there’s something semantically wrong with the body of the request. This can be due to malformed JSON, a parameter that’s missing or the wrong type, or trying to perform an action that doesn’t make any sense. Check the response body for specific information about what went wrong."

"Invalid release_id:expected integer" is displayed as a message.

My get methods work but post doesn't.

int release_id;
String condition;
int listing_id;
String sleeve_condition;
String comments;
String allow_offers;
string status;
String external_id;
String location;
string weight;
String format_quantity;
private Double price = Double.valueOf(0);

json = doPost("/marketplace/listings?release_id=" + product.getRelease_id() + "&sleeve_condition=" + product.getCondition() + "&price=" +product.getPrice());

"https://api.discogs.com/marketplace/listings?release_id=1113859&condition=poor&price=2000.0&status=Mint"



   WebResource webResource = initRest(restUrl);
    ClientResponse resp = webResource.type("application/json")
            .header("Authorization", "Discogs token=" + token)
            .header("JTLSyncTool/0.1", "+https://#####")
            .post(ClientResponse.class);

Does anyone have an idea?

Thanks everyone!

1

There are 1 answers

0
Vildanb On

To test the working of the code, I wrote it directly as follows.

json = doPost("/marketplace/listings?release_id="+1113859+"&status=Draft"
                      +"&condition="+"Mint%20(M)"+ "&price=" +2000.0);



 protected static JSONObject doPost(String restUrl) {
        JSONObject json = null;

        WebResource webResource = initRest(restUrl);
        ClientResponse resp = webResource.type("application/json")
                .header("Authorization", "Discogs token=" + token)
                .header("JTLSyncTool/0.1", "+https://www.####.de")
                .post(ClientResponse.class);
        json = parseRest(json, resp);
        if(resp.getStatus() > 250) {
            PersistenceHelper.addError(DiscogsApi.class.getName(), restUrl);
            PersistenceHelper.addError(DiscogsApi.class.getName(), resp.toString());
        }

        return json;
    }