> ## Documentation Index
> Fetch the complete documentation index at: https://upstash-vector.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Produce Messages Using REST API

<Info>
  If you do not have a Kafka cluster and/or topic already, follow [these
  steps](../overall/getstarted) to create one.
</Info>

In the cluster details section of the
[Upstash Console](https://console.upstash.com), scroll down the **REST API**
section and and copy `UPSTASH_KAFKA_REST_URL`, `UPSTASH_KAFKA_REST_USERNAME` and
`UPSTASH_KAFKA_REST_PASSWORD` using the copy icons next to them.

<Frame>
  <img src="https://mintlify.s3-us-west-1.amazonaws.com/upstash-vector/img/kafka/getting_started/connect-rest.png" />
</Frame>

We will use a `Node.js` sample code to show how to produce message(s) using the
REST API. Our sample will use a topic named `cities` and send a few city names
to this topic.

Replace following parameters in the code snippets below with your actual values.

```js
const address = "https://tops-stingray-7863-eu1-rest-kafka.upstash.io";
const user = "G9wcy1zdGluZ3JheS03ODYzJMUX";
const pass = "eUmYCkAlxEhihIc7Hooi2IA2pz2fw==";
const auth = Buffer.from(`${user}:${pass}`).toString("base64");
const topic = "cities";
```

Following code will produce three city names to a topic:

```js
async function produce(topic, msg) {
  const response = await fetch(`${address}/produce/${topic}/${msg}`, {
    headers: { Authorization: `Basic ${auth}` },
  });
  const metadata = await response.json();
  console.log(
    `Topic: ${metadata.topic}, Partition: ${metadata.partition}, Offset: ${metadata.offset}`
  );
}

produce(topic, "Tokyo");
produce(topic, "Istanbul");
produce(topic, "London");
```

Alternatively we can post all cities using a single request, instead of
producing them one-by-one. Note that in this case, URL does not have the message
argument but instead all messages are posted in the request body.

```js
async function produceMulti(topic, ...messages) {
  let data = messages.map((msg) => {
    return { value: msg };
  });
  const response = await fetch(`${address}/produce/${topic}`, {
    headers: { Authorization: `Basic ${auth}` },
    method: "POST",
    body: JSON.stringify(data),
  });
  const metadata = await response.json();
  metadata.forEach((m) => {
    console.log(
      `Topic: ${m.topic}, Partition: ${m.partition}, Offset: ${m.offset}`
    );
  });
}

produceMulti(topic, "Tokyo", "Istanbul", "London");
```

For more info about using the REST API see
[Kafka REST Produce API](../rest/restproducer) section.
