Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

jaincjacob@gmail.com avatar image
jaincjacob@gmail.com asked Erick Ramirez commented

Getting authorization error while adding rows in table using REST API

Getting the following error:

{
  "description": "Role unauthorized for operation: Invalid clientID or hash provided",
  "code": 401
}

Tried out using REST API (from postman) and using nodejs driver in both case got the authorization error.

in postman used the header: X-Cassandra-Token

in nodejs client used: username and password config

Any help is appreciated

stargateauthorization
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered Erick Ramirez commented

The error you posted indicates that either (a) the credentials are invalid, or (2) the role you're using does not have write permissions.

You didn't mention if you're connecting to an Astra database but if you are, you need to create an application token with API access, for example an API Admin User role or API R/W User role:

c11362-astra-roles.png

You will need to use the token which starts with AstraCS:* in the header. For example:

"request": {
  "method": "POST",
  "header": [
    {
      "key": "X-Cassandra-Token",
      "value": "AstraCS:dDqWQdIUPhJJdClSRqWKlnlk:4b291e6028a2ff2e94601c6d76cbff03dda937a6214d3ea6659d79e0a37a3905"
    },
    {
      "key": "Content-Type",
      "value": "application/json"
    }
  ],

For details, see the page Developing your app with the REST API.

For Node.js, you need to create an application token with read and write access such as a R/W Svc Acct role or a R/W User role.

You will then need to set the username to the client ID and the password to the client secret in your code. For example:

  const client = new Client({
    cloud: { secureConnectBundle: '/path/to/secure-connect-bundle.zip' },
    credentials: { username: 'dDqWQdIUPhJJdClSRqWKlnlk', password: 'JSARC+yR6zenI+q,,JItp06+BC6OxK4eNNP_XqGzQZQOFvzt2xJQmODA7UcFX.04+fKBrDGJwqAOrABuQWZehccU1W,52LkMplhJJcLirmLdY68jPXIzv5re.PU+MGPw' }
  });

For details, see Developing your app with the Node.js driver. Cheers!


5 comments Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Thank you for your response. To explain further, Yes I had followed the instruction that you mentioned above and generated token to connect to astra db as show below; but got authorization error. One thing I didn't do is the setting environment; is this required for accessing by Rest API?

export ASTRA_DB_ID=<database_id> export ASTRA_DB_REGION=<database_region> export ASTRA_DB_KEYSPACE=<keyspace_name> export ASTRA_DB_APPLICATION_TOKEN=<app_token>

Attaching the error

1621231366454.png

0 Likes 0 ·
1621231366454.png (39.2 KiB)
Erick Ramirez avatar image Erick Ramirez ♦♦ jaincjacob@gmail.com ·

You only need to set environment variables if you're accessing the REST API from the command line. For example, if you were running curl commands.

But again, you need to use an API* role which has write permissions. Cheers!

0 Likes 0 ·

Thanks. I was not using curl command; was trying it from postman and the token I used had "API Admin User" role.

Just tried again this morning without any change and it worked :) Thank you!

1621270966894.png

0 Likes 0 ·
1621270966894.png (25.8 KiB)
Show more comments
smadhavan avatar image smadhavan ♦ jaincjacob@gmail.com ·

@jaincjacob@gmail.com, if you have downloaded the CSV file when you created the token, it should have a column that details what type of role with which you created that token and you would check to make sure it has API* role with write permissions.

0 Likes 0 ·