Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How can I get the token to use the REST API in a user and password protected instance of NiFi?

avatar
Explorer

Hi,

I have a NiFi instance running on a Docker container and, and I'd like to get some information about it through its API. To do so, I have followed the steps indicated here: https://community.hortonworks.com/questions/96383/how-to-get-the-access-token-by-invoking-nifi-rest.... using this command:

curl 'http://<my_nifi_ip>:<my_nifi_port>/nifi/nifi-api/access/token' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data 'username=<my_user>&password=<my_password>' --compressed

But, when launching this command, it redirects me to the login page of NiFi

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

<html><head>

<title>302 Found</title>

</head><body>

<h1>Found</h1>

<p>The document has moved <a href="/login.html">here</a>.</p>

</body></html>

How can I solve my problem to get the token?


Thank you for your help. Regards.

1 REPLY 1

avatar

Hi @CarlosHS,


inorder to perform CURL/REST APi with Nifi, you might need a access token ,

as per blog :

following command will get you the access token

curl 'https://nifi-host:port/nifi-api/access/token' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data 'username=ldap-username&password=ldap-password' --compressed —insecure

Later this token need to be reused for all operations like :

curl -k ’https://nifi-host:port/nifi-api/flow/process-groups/root/status' -H “Authorization: Bearer $token”


hope this helps