4

I have created ".netrc " file on my machine and trying below databricks rest api call. But it always giving an unauthorized error. How to create .netrc file in Databricks?

curl -n -X GET https:///api/2.0/token/list

How to use .netrc file with databricks api?

Rohi_Dev_1.0
  • 372
  • 1
  • 2
  • 19

2 Answers2

3

My .netrc file looks like this:

machine northeurope.azuredatabricks.net
login token
password dapicxxxxxxxxxxxxxxxxxxxxx

Machine should be the region where your workspace is deployed, login is always token and the password the token created for your user.

See Databricks documentation how to create the token.

Hauke Mallow
  • 2,887
  • 3
  • 11
  • 29
  • Can't we log in using UserId and password? – Rohi_Dev_1.0 Aug 14 '18 at 04:41
  • You have to generate a token in the Databricks- UI. This is your Password. Login is always token. You don't use your userid/ pwd. – Hauke Mallow Aug 14 '18 at 05:00
  • actually, my main purpose to generate .netrc file is to generate token automatically. I want to deploy Data Factory Databricks activity and for that I need User Token. Is there any other way to generate token? – Rohi_Dev_1.0 Aug 14 '18 at 05:32
  • You need an initial token to authenticate. Then you can also use the API for token management, see also https://docs.azuredatabricks.net/api/latest/tokens.html . – Hauke Mallow Aug 14 '18 at 05:47
  • You need an initial token to authenticate. Then you can also use the API for token management, see also https://docs.azuredatabricks.net/api/latest/tokens.html . – Hauke Mallow Aug 14 '18 at 05:49
  • Yes. the same thing I am trying. But to create the token I have to pass token in the authorization header. So I am trying to use curl command for this. I read here that using .netrc file we can authenticate API request. https://docs.azuredatabricks.net/api/latest/authentication.html. – Rohi_Dev_1.0 Aug 14 '18 at 08:30
  • Yes, but the first token has to be created in the UI, unfortuanetly the first token can not be created via the REST API. – Hauke Mallow Aug 15 '18 at 11:38
  • Is it possible using Databricks CLI? – Rohi_Dev_1.0 Aug 16 '18 at 06:17
  • What about more than 1 token? What is the format in .netrc file? – NullPumpkinException Dec 19 '22 at 23:49
0

Easier way to configure databricks cli is to install databricks-cli package using the below command

pip install --upgrade databricks-cli

Then:

databricks configure --token (enter hostname/auth-token at prompt)

Instructions are available at https://pypi.org/project/databricks-cli/

jalazbe
  • 1,801
  • 3
  • 19
  • 40