> ## Documentation Index
> Fetch the complete documentation index at: https://docs.streamnative.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Message Rest API QuickStart

## Set up Message Rest API

Before using Rest API, you need to complete the following setup steps.

### Step 1: Create a service account

<Note title="Note">
  Currently, you can't edit a service account. If you need a service account to have Super Admin access, make sure to enable it when creating the service account. By default, service accounts do not have Super Admin enabled.
</Note>

To create a service account, follow these steps.

1. On the left navigation pane, click **Service Accounts**.

2. Click **Create Service Account**.

3. (Optional) Select **Super Admin** to grant the service account with Super admin access to a namespace or tenant.

4. Enter a name for the service account, and then click **Confirm**.

### Step 2: Create an API key of your service account

<Note title="Note">
  Before using an API key, verify that the service account is authorized to access the resources, such as tenants, namespaces, and topics.
</Note>

You can follow the instructions to [create an API key](/cloud/security/authentication/service-accounts/use-api-keys/api-keys-overview#using-api-keys-to-connect-to-your-cluster) for the service account you choose to use.

### Step 3: Grant service account permissions

<Note title="Note">
  If you use a Super Admin service account, you can skip this step because a Super Admin service account has the required permissions already.
</Note>

1. On the left navigation pane, in the **Admin** section, click **Tenants/Namespaces**.

2. Select the **Public** tenant, then select the **Default** namespace under the tenant.

3. Select the **POLICY** tab.

4. In the **Authorization** area, click **ADD ROLE**, and select the name of the service account you just created in the previous section.

5. In the **Authorization** area, on the drop-down menu below the service name you just added, select the **consume** and **produce** roles. The roles are added to your service account.

### Step 4: Get the HTTP Service URL of your StreamNative cluster

To get the service URL(s) of a StreamNative cluster, follow these steps.

<Tabs>
  <Tab title="StreamNative Console">
    1. Navigate to the **Cluster Dashboard** page by [switching to the cluster workspace](/cloud/get-started/cloud-console#switch-a-cluster).

    2. On the **Cluster Dashboard** page, click **Details** tab.

    3. You will see the available service URLs in the **Access Points** area.

    4. You can click **Copy** at the end of the row of the service URL that you want to use.
  </Tab>
</Tabs>

## Work with Message Rest API

<Note title="Note">
  Rest API does not validate the data schema and directly stores the accepted binary data into a topic. You should ensure the correctness of the data schema to ensure compatibility with the Pulsar client in other languages.
</Note>

After you have completed the configuration steps above, you can use Rest API to produce and consume messages. Rest API sends binary data. You can use the cURL tool to encode a string (for example `Hi Pulsar`) into UTF-8 format bytes. To send bytes in another format, you need to specify an appropriate file. For more information, see the [cURL documentation](https://everything.curl.dev/http/post/binary).

1. Create a subscription on the topic.

   ```shell script theme={null}
   curl -X PUT https://<endpoint>:<port>/admin/v2/persistent/public/default/rest-topic/subscription/rest-sub \
     --header 'Authorization: Bearer <API Key>' \
     --header 'Accept: application/json' \
     --header 'Content-Type: application/json'
   ```

   You should see the following output:

   ```shell script theme={null}
   # No content response
   ```

2. Produce messages to the topic.

   ```shell script theme={null}
   curl -X POST https://<endpoint>:<port>/admin/rest/topics/v1/persistent/public/default/rest-topic/message \
     --header 'Authorization: Bearer <API Key>' \
     --header 'Accept: application/json' \
     --header 'Content-Type: application/octet-stream' \
     --data-binary 'Hi, Pulsar'
   ```

   You should see the following output:

   ```shell script theme={null}
   # Message id in string format
   10:0:-1:0
   ```

3. Consume messages from the topic.

   ```shell script theme={null}
   curl -X POST https://<endpoint>:<port>/admin/rest/topics/v1/persistent/public/default/rest-topic/rest-sub/message \
     --header 'Authorization: Bearer <API Key>' \
     --header 'Accept: application/octet-stream' \
     --header 'Content-Type: application/json' -v
   ```

   You should see the following output:

   ```shell script theme={null}
   # Headers
   X-Pulsar-Message-Id: CAoQACAAMAE=
   X-Pulsar-Message-String-Id: 10:0:-1:0
   X-Pulsar-Sequence-Id: 0

   # Body
   Hi, Pulsar
   ```

4. Acknowledge messages.

   ```shell script theme={null}
   curl -X PUT https://<endpoint>:<port>/admin/rest/topics/v1/persistent/public/default/rest-topic/rest-sub/message \
     --header 'Authorization: Bearer <API Key>' \
     --header 'Accept: application/json' \
     --header 'Content-Type: application/json' \
     --data-raw 'CAoQACAAMAE='
   ```

   You should see the following output:

   ```shell script theme={null}
   # No content response
   ```

5. Negative acknowledge messages.

   ```shell script theme={null}
   curl -X PUT https://<endpoint>:<port>/admin/rest/topics/v2/persistent/public/default/rest-topic/rest-sub/message \
     --header 'Authorization: Bearer <API Key>' \
     --header 'Accept: application/json' \
     --header 'Content-Type: application/json' \
     --data-raw '{"encodedMessageId":"CAoQACAAMAE=","negativeAck":"true"}'
   ```

   You should see the following output:

   ```shell script theme={null}
   # No content response
   ```

## Message Rest API reference

For further information, see [Message Rest API reference](/api-references/rest-messaging-api/rest-messaging-api).
