Member since
08-29-2022
7
Posts
0
Kudos Received
0
Solutions
04-12-2023
07:22 AM
1 Kudo
you can use Keycloak to authenticate and obtain a token, which you can then use to make the GET request to the API. Here's an example of how you can do this:Set up a Keycloak client for your API. You can follow the Keycloak documentation to set up a client for your API.Use the Keycloak API to obtain an access token. You can use the /auth/realms/{realm_name}/protocol/openid-connect/token endpoint to obtain an access token. You will need to provide your Keycloak username and password, as well as the client ID and client secret for your API. Here's an example of how you can use the requests library in Python to obtain an access token:
import requests
url = 'http://<KEYCLOAK_HOST>/auth/realms/<REALM_NAME>/protocol/openid-connect/token'
payload = { 'client_id': '<CLIENT_ID>', 'client_secret': '<CLIENT_SECRET>', 'username': '<USERNAME>', 'password': '<PASSWORD>', 'grant_type': 'password' }
response = requests.post(url, data=payload)
access_token = response.json()['access_token']
This code will make a POST request to the Keycloak token endpoint and obtain an access token.
Use the access token to make the GET request to the API. You can use the Authorization header to include the access token in the GET request. Here's an example of how you can use the requests library in Python to make the GET request:
import requests
url = 'http://<API_HOST>/api/<API_ENDPOINT>'
headers = { 'Authorization': 'Bearer ' + access_token }
response = requests.get(url, headers=headers)
data = response.json()
You can use the ExecuteScript processor in NiFi to execute the Python code and obtain the data from the API. You can use the InvokeHTTP processor to make the initial GET request to the Keycloak sign-in page and extract the necessary information, such as the Keycloak username and password, to use in the Python code. You can use NiFi's built-in ExtractText processor to extract the necessary information from the InvokeHTTP response.
This code will make a GET request to the API with the access token included in the Authorization header. Sincerely, Hannah
... View more
03-22-2023
08:45 AM
@Jacccs Did you solve your problem? I have a similar case
... View more
09-01-2022
12:05 PM
Hi , you can use QueryRecord Processor. For more information please see: https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.12.1/org.apache.nifi.processors.standard.QueryRecord/additionalDetails.html If you find this helpful please accept solution. Thanks
... View more
08-31-2022
03:02 PM
1 Kudo
Hi , Not sure if this is possible with out of the box processor. I can think of ReplaceText first to replace different delimiters like (-) or white-space (\s) to common delimiter like (,) however if there is a white space before or after other delimiters like (-) or (,) its not going to work. Another option is to use ExecuteScript processor where you try to read each line (after the header) from the flowfile content and then use string split function and try it with different delimiter, once you get two array elements you construct your new string with the new column header and delimiter and transfer to the success relationship.
... View more