DataStax Astra Developer Hub

Welcome to the DataStax Astra Developer Hub. You'll find comprehensive guides and documentation to help you start working with DataStax Astra as quickly as possible. Use the included APIs to create, modify, and terminate databases, and interact with the databases you create. Let's do it!

Astra Docs      API Reference      CQL for Astra

Add rows to your table

Insert data into your tables using Astra's REST API.

After creating a tabletable - Stores data based on a primary key, which consists of a partition key and optional clustering columns. A partition key defines the node on which the data is stored, and divides data into logical groups. Define partition keys that evenly distribute the data and also satisfy specific queries. Query and write requests across multiple partitions should be avoided if possible. A clustering column defines the sort order of rows within a partition. When defining a clustering column, consider the purpose of the data. For example, retrieving the most recent transactions, sorted by date, in descending order. in your keyspacekeyspace - The defining container for replication, similar to a schema in a relational database. All tables belong to a keyspace. Each keyspace can contain as many as 200 tables., you can add rows of data. Use the Add rows endpoint to add rows to the table you created in the last step.

Prerequisites

  1. Generate an authorization token.
  2. Create a table in your keyspace.

Procedure

  1. Copy the following request, which you use to add rows to a tabletable - Stores data based on a primary key, which consists of a partition key and optional clustering columns. A partition key defines the node on which the data is stored, and divides data into logical groups. Define partition keys that evenly distribute the data and also satisfy specific queries. Query and write requests across multiple partitions should be avoided if possible. A clustering column defines the sort order of rows within a partition. When defining a clustering column, consider the purpose of the data. For example, retrieving the most recent transactions, sorted by date, in descending order. in the specified keyspace.
curl --request POST \
  --url https://${ASTRA_CLUSTER_ID}-${ASTRA_CLUSTER_REGION}.apps.astra.datastax.com/api/rest/v1/keyspaces/{my_keyspace}/tables/{table_name}/rows \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --header 'x-cassandra-request-id: {unique-UUID}' \
  --header "x-cassandra-token: ${ASTRA_AUTHORIZATION_TOKEN}" \
  --data '{"columns":[
  {"name":"name0","value":"value0"},
  {"name":"name1","value":"value1"},
  {"name":"name2","value":"value2"},
  {"name":"name3","value":"value3"},
  {"name":"name5","value":"value4"}]}'
  1. Replace the following values with the values for your databasedatabase - A group of distributed instances for storing data. Each paid Astra database has at least three instances.:
  • Modify my_keyspace to match the name of your keyspace.
  • Replace table_name with the name of the table you want to create. In this example, enter products as the table name.
  • Enter a {unique-UUID} for the request.
  • In the --data option of the call, use the columns parameter to define each rowrow - 1) Columns that have the same primary key. 2) A collection of cells per combination of columns in the storage engine..

In each row, name indicates the columncolumn - The smallest increment of data, which contains a name, a value, and a timestamp. Also known as a cell. name and value indicates the corresponding value. For example, the following definition adds a row for the Heavy Lift Arms product, including a description, price, and created timestamp.

Example:

curl --request POST \
  --url https://${ASTRA_CLUSTER_ID}-${ASTRA_CLUSTER_REGION}.apps.astra.datastax.com/api/rest/v1/keyspaces/betterbotz/tables/products/rows \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --header 'x-cassandra-request-id: xyzaa27b-de8e-4afc-8431-8f06a326047d' \
  --header "x-cassandra-token: ${ASTRA_AUTHORIZATION_TOKEN}" \
  --data '{"columns":[{"name":"id","value":"e9b6c02d-0604-4bab-a3ea-6a7984654631"},{"name":"name","value":"Heavy Lift Arms"},{"name":"description","value":"Heavy lift arms capable of lifting 1,250 lbs of weight per arm. Sold as a set."},{"name":"price","value":"4199.99"},{"name":"created","value":"2012-04-23T18:25:43.511Z"}]}'
  1. Run the cURL call to add the rows you defined to the products table in the specified keyspace. If the call is successful, a message returns indicating that the operation was successful, and the number of rows that were modified:
    {"success": true,"rowsModified": 1}

Updated 25 days ago



Add rows to your table


Insert data into your tables using Astra's REST API.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.