javasendinblue

"Unacceptable content-type" when creating contact via Java client of sendinblue API


Really strange as I copy paste the code sample from the sendinblue API doc:

OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/octet-stream");
RequestBody body = RequestBody.create(mediaType,"\"updateEnabled\":false,\"email\":\"example@email.com\"}");
Request request = new Request.Builder()
  .url("https://api.sendinblue.com/v3/contacts")
  .post(body)
  .addHeader("accept", "application/json")
  .addHeader("content-type", "application/json")
  .addHeader("api-key", "xxxxxxxxxxxxxxxxxx")
  .build();

Response response = client.newCall(request).execute(); 

The response is:

response code is: 406

response message is: Not Acceptable

response body is: {"code":"not_acceptable","message":"Unacceptable content-type"}

I use this Java client:

<dependency>
    <groupId>com.sendinblue</groupId>
    <artifactId>sib-api-v3-sdk</artifactId>
    <version>3.0.1</version>
</dependency>

Solution

  • You need to set the content-type in as JSON (application/json).