Confluent REST Proxy POST to Topic responds with HTTP 415 Unsupported Media Type

517 Views Asked by At

I created a topic, test-topic, successfully. When I attempt to produce data for the topic with the curl command:

curl -v -X POST -H "Content-Type: application/json" -H "Accept: application/json" \
     --data '{"records":[{"key":"jsmith","value":"alarm clock"}, \
     {"key":"htanaka","value":"batteries"},{"key":"awalther","value":"bookshelves"}]}' \
     "http://localhost:8082/topics/test-topic"

I get the following response:

{"error_code":415,"message":"HTTP 415 Unsupported Media Type"}

I see this exception in the Docker log:

rest-proxy | [2023-07-08 07:40:46,829] ERROR Request Failed with exception (io.confluent.rest.exceptions.DebuggableExceptionMapper) rest-proxy | javax.ws.rs.NotSupportedException: HTTP 415 Unsupported Media Type rest-proxy | at org.glassfish.jersey.server.internal.routing.MethodSelectingRouter.getMethodRouter(MethodSelectingRouter.java:421)... POST /topics/test-topic HTTP/1.1" 415 62 "-" "curl/7.87.0" 4 (io.confluent.rest-utils.requests)

Tried changing Content-Type: "Content-Type: application/vnd.kafka.json.v3+json", but behaved the same.

Any insights appreciated.

2

There are 2 best solutions below

0
Sam S. On

See the README.md for the REST Proxy. The format and URL for the V3 API is different from the V2. Confluent's QuickStart pages have not been updated.

Here's a V3 curl post of a single data value:

curl -X POST -H "Content-Type: application/json" \
   -d '{"value":{"type":"JSON","data":{"name":"testUser"}}}' \
   http://localhost:8082/v3/clusters/xFhUvurESIeeCI87SXWR-Q/topics/jsontest/records

Here's a V3 curl post of multiple data values:

curl -X POST -H "Content-Type: application/json" \
   -d '{"value":{"type":"JSON","data":"ONE"}} {"value":{"type":"JSON","data":"TWO"}}' \
   http://localhost:8082/v3/clusters/xFhUvurESIeeCI87SXWR-Q/topics/jsontest/records
0
Sam S. On

The above examples from the README.md file did not provide a Kafka key value. Here's are examples with key values that can be used with partitioning placement of data.

Single value:

curl -v -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
--data '{"key": {"type": "JSON", "data": 110179}, "value": {"type": "JSON", "data": {"field1": "value1"}}}' \
http://localhost:8082/v3/clusters/vn6t4eKOSqKAMJLIDu-0eg/topics/rtc/records

Multiple values:

curl -v -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
--data '{"key": {"type": "JSON", "data": 111}, "value": {"type": "JSON", "data": {"field1": "value1"}}} {"key": {"type": "JSON", "data": 222}, "value": {"type": "JSON", "data": {"field2": "value2"}}}' \
http://localhost:8082/v3/clusters/vn6t4eKOSqKAMJLIDu-0eg/topics/rtc/records