0

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.

Sam S.
  • 1
  • I used the docker-compose.yml file here on GitHub: [cp-all-in-one-community/docker-compose.yml](https://github.com/confluentinc/cp-all-in-one/blob/7.4.0-post/cp-all-in-one-community/docker-compose.yml) – Sam S. Jul 10 '23 at 01:46
  • If you are looking for a way to post JSON into Kafka there are other options for a REST proxy. Zilla is one open-source option https://docs.aklivity.io/zilla/latest/tutorials/quickstart/kafka-proxies.html – A.J. Jul 14 '23 at 19:41
  • Thanks for the Zilla link. Interesting to see another option. – Sam S. Jul 23 '23 at 02:28

2 Answers2

0

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
Sam S.
  • 1
0

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
Sam S.
  • 1