Created 07-14-2022 03:26 AM
I am trying to design a flow, where I get file details from a Sharepoint site's directory.
For this I need to make 4 or more REST calls:
1. Get access token from microsoft.
2. Use the access token from previous JSON, to get site details.
3. Use the site id from previous JSON, to get drive details.
4. Use the drive id from previous response JSON , to list drive children.
What would be the best approach to implement this in NiFi?
Created 07-14-2022 05:09 AM
ExtractText processor can help you grab needed information from json content and store in the flow file attribute for reuse after InvokeHTTP.
Created 07-14-2022 06:23 AM
Agree with @ckumar's response. It would be difficult to provide more detail without understanding the actual structure needed for the follow-on rest-api calls. What info is expected in headers versus raw data.
Typically the access token is sent in a header and is often needed in all subsequent rest-api calls. Do you need to create unique FlowFile content to send as data?
The ExtractText can be used to extract the token from the response written to the FlowFiles content and added as an attribute on the FlowFile before next invokeHTTP processor. Since I do not know much about Sharepoint or the format of the responses received, I can only give an example based on a returned token from NiFi's rest-api:
The entire response body would be placed in a FlowFile attribute named "token".
In the case of the NiFi token, I must then build a proper "Authorization" header with that token before being able to make additional rest-api calls using it. To do that, you can use an UpdateAttribute processor:
So here I added "Bearer " to the token and write it to a new FlowFile attribute "Authorization"; although, you could also simply update the existing "token" attribute instead.
Then in the next InvokeHTTP processor you can pass this "Authorization" FlowFile attribute value in a header by adding a dynamic property:
Beyond this, you can do similar with your follow on responses assuming each step simply requires you to use the response values you extracted as headers or custom rest-api remote URLs.
If you found any of the response received help you address your query, please take a moment to login and then click "Accept as Solution" on every response that helped.
Hopefully this helps you reach your end goal here,
Created 07-14-2022 06:43 AM
Created 07-14-2022 09:12 AM
so this looks doable as I described above. Not sure what program you are using in your screenshots as it does not show the full rest-api call structure.
But your process would be as as follows:
1. Get bearer token
2. Extract bearer token from response body and place in FlowFile attribute
3. Format flowfile attribute as needed for use by the rest of the api-calls
4. Using bearer token make get request to the ../sites rest-api endpoint
5. Use ExtractText to extract the site id to a new FlowFile Attribute
6. Use bearer token again and use NiFi Expression Language to dynamically create the rest-api url to include the site id.
7. From response, extract the Drive id to another new FlowFile Attribute as above.
8. Use bearer token again and use NiFi Expression Language to dynamically create the rest-api url to include the drive id.
9 finally do whatever you need to do with the response json you get from that final rest-api call.