Support Questions

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

In Apache Nifi Rest API, what is difference between Import and Upload?

avatar
New Contributor
 
1 ACCEPTED SOLUTION

avatar
Master Guru
hide-solution

This problem has been solved!

Want to get a detailed solution you have to login/registered on the community

Register/Login
5 REPLIES 5

avatar
Master Guru
hide-solution

This problem has been solved!

Want to get a detailed solution you have to login/registered on the community

Register/Login

avatar
New Contributor

Thank you @Shu

I was able to upload to my NiFi instance using following curl:

curl -XPOST http://<nifihost:nifiport>/nifi-api/process-groups/<id>/templates/upload -k -v -F template=@/path/to/template.xml

I am now tryin to import into NiFi Canvas but am unable to formulate the right command for this. Can you help me with correct curl to import the uploaded template onto the canvas?

avatar
Master Guru
@Tommy Lathrop

To import the Template into NiFi Canvas we need to use specific syntax of curl command and template-instance

curl -i -X POST -H 'Content-Type:application/json' -d '{"originX": 2.0,"originY": 3.0,"templateId": "<template-id>"}' http://localhost:8080/nifi-api/process-groups/<process-group-id>/template-instance

Here is what i tried

I'm having a template in my Downloads folder

1.To upload a template from Downloads folder to NiFi i used below curl with upload method

curl -X POST http://localhost:8080/nifi-api/process-groups/226b1e5f-0160-1000-deb0-791f1a6f1f00/templates/upload -k -v -F template=@/cygdrive/c/shu/Downloads/Count_Loop.xml

in the above curl i'm using POST and my process group id is 226b1e5f-0160-1000-deb0-791f1a6f1f00

??Why we need to specify process group id while uploading??

Templates are owned by a process group (whether that is the root process group or one nested in the canvas). You can upload templates by making use of the '/process-groups/{id}/templates/upload' to upload a template to a particular process group.

Then i have given the path to the my Count_Loop.xml file and uploaded the template into NiFi Instance.

2.Now we need to import the Uploaded Count_Loop.xml into NiFi canvas

For this case we need to have our Template ID, For this id

Curl http://localhost:8080/nifi-api/flow/templates

Hit the above API and get the Template id for the Uploaded template for my case my template id is 02a4b939-ac14-4fac-9f05-550cc521b317.

Then we need to instantiate the template by using POST method and template-instance

POST
/process-groups/{id}/template-instance

My command is as follows

curl -i -X POST -H 'Content-Type:application/json' -d '{"originX": 2.0,"originY": 3.0,"templateId": "02a4b939-ac14-4fac-9f05-550cc521b317"}' http://localhost:8080/nifi-api/process-groups/226b1e5f-0160-1000-deb0-791f1a6f1f00/template-instance

i'm importing the uploaded Count_Loop.xml into the ProcessGroupID 226b1e5f-0160-1000-deb0-791f1a6f1f00 ,we got template id before so i'm using the TemplateID 02a4b939-ac14-4fac-9f05-550cc521b317 in the above curl method.

This template instance expects origin x, y and template id for sure. If you are missing any of these parameters then it results Bad request error.

If the Answer helped to resolve your issue, 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 errors.

avatar
New Contributor

Thank you @Shu

avatar
New Contributor
Is it always two step process for XML import, Can I not directly copy the flow or import to the flow to the canvas ?


I understand in Upload and Import there will be always a template copy created for any flow that has to be imported to the canvas.


Scenario:

I have one flow (xml), I will have to create ten copies/instance of this flow (with different source/target).


I know we can import ten times from one template after uploading (one time) and then update the variables again by Rest API.

But I want to update the parameters/variables in xml file itself and then directly import to canvas for some reasons. Is it possible ?