Support Questions

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

I am getting 'Unable to find snippet with id #IdNum ' while creating template using NIFi API. Can anyone help me in finding out the reason.

avatar
Explorer

I am doing a small POC in which I want to create a template using NiFi Rest API.

I have first used nifi-api/flow/process-groups/parentProcessGroupUUID API to fetch Process Group details. The process that I have used is a single processor (invokeHTTP) process.I have successfully got response for this API. API url used by me is

http://hostname:port/nifi-api/flow/process-groups/688f3e9f-0163-1000-2c60-a8fcd62f0965

After first step I have tried nifi-api/snippets API to get a snippet Id.I have successfully received the response.Below are the request and response details.

API url: http://hostname:port/nifi-api/snippets (POST)

Request:

{ "snippet": { "parentGroupId": "688f3e9f-0163-1000-2c60-a8fcd62f0965", "processors": {}, "funnels": {}, "inputPorts": {}, "outputPorts": {}, "remoteProcessGroups": {}, "processGroups": { "688f3e9f-0163-1000-2c60-a8fcd62f0965": { "clientId": "688f3e9f-0163-1000-2c60-a8fcd62f0965", "version": 1 } }, "connections": {}, "labels": {} } }

Response:

{ "snippet": { "id": "917095c4-0163-1000-3b8d-2a95f3a9d1fe", "uri": "http://hostname:port/nifi-api/process-groups/688f3e9f-0163-1000-2c60-a8fcd62f0965/snippets/917095c4-0163-1000-3b8d-2a95f3a9d1fe", "parentGroupId": "688f3e9f-0163-1000-2c60-a8fcd62f0965", "processGroups": { "688f3e9f-0163-1000-2c60-a8fcd62f0965": { "clientId": "688f3e9f-0163-1000-2c60-a8fcd62f0965", "version": 1 } }, "remoteProcessGroups": {}, "processors": {}, "inputPorts": {}, "outputPorts": {}, "connections": {}, "labels": {}, "funnels": {} } }

Finally I tried to hit nifi-api/process-groups/ParentProcessGroupUUID/templates API.But getting error 'Unable to find snippet with id '917095c4-0163-1000-3b8d-2a95f3a9d1fe'. Below are the details

API url:http://hostname:port/nifi-api/process-groups/688f3e9f-0163-1000-2c60-a8fcd62f0965/templates (POST)

Request:

{ "name": "Template_24_05_01", "description": "Template_24_05_01 created", "snippetId": "917095c4-0163-1000-3b8d-2a95f3a9d1fe" }

Response:

Unable to find snippet with id '917095c4-0163-1000-3b8d-2a95f3a9d1fe'.

I am new to NiFi. I will highly appreciate any help.

5 REPLIES 5

avatar
Explorer

To add some more information:

I am getting response 'A process group in this snippet could not be found.' initially. The response message 'Unable to find snippet with id....' may be related to time elapsed between generation of snippet id and hitting next API.

avatar
Master Guru
@neeraj sharma

I think the issue is because of time in between snippet and template api calls.

73004-snippet.png

in NiFi rest api docs it states snippet will be discarded if not used in a subsequent request after 1 minute.

Create snippet and grad the snippet id and make curl call using the snippet id with in 1 minute.

**Note:

every create snippet api call creates new snippet id and we have to use the newly created snippet id in template creation curl api call.

Refer to this link for more information about NiFi rest api.

Let us know if you are facing any issues..!!

avatar
Master Guru
@neeraj sharma

The issue is because of using the processor id not the parent process groupid while creating template using snippetId, As NiFi not able to find out the parent process groupid that you are having in your curl api call.

Make sure you have used the parent process group id in your api call, in your case you are having InvokeHttp processor in NiFi canvas and to get Parent Process group id click on the canvas(not on any processor in the canvas) and get the processor group id then use the id in your api call.

curl -i -H 'Content-Type: application/json' -X POST -d '{"name":"Template_24_05_01","description":"","snippetId":"<snippet_id>"}' http://localhost:8080/nifi-api/process-groups/<parent_processor_groupId>/templates

I would suggest to use Chrome/Firefox developer tools and create a template using NiFi UI way and see all the API calls that are making while creating template this way gives you more clear picture how to create templates, Then use NiFi RestAPI(curl) to create templates.

Let us know if you are still facing issues..!!

avatar
Master Guru
@neeraj sharma

If the answer addressed your question,Take a moment to Log in and Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues and close this thread.

avatar
Explorer

I have tried to hit template creation call within 1 minute of snippet creation but I am getting response 'A process group in this snippet could not be found.' in that case. Any idea why I am getting this response.