Reply

Import "Lists" via API?

Authority
Posts: 29
3915     0

 

Currently, I manually import lists via Config Managment>Job Management>Lists>Import

 

Wondering if there is method to import via a script where it could replace the existing list.

 

Thanks.

Re: Import "Lists" via API?

Adviser
Posts: 470
3915     0

Here is the API - /api/3.1/config_lists/import?file=test.csv

 

Remember if you are using cURL or any PUT method

-X POST -H "Content-Type: multipart/form-data" -F "file_name=@test.csv" netmri/api/3/config_lists/import?file=test.csv"
Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

https://sifbaksh.com

Re: Import "Lists" via API?

Authority
Posts: 29
3915     0

Sorry. I've never used cURL.  Can you provide the full syntax?

 

Also, I noticed there are an uneven number for double-quotes ".

 

Thanks.

Re: Import "Lists" via API?

Authority
Posts: 29
3915     0

FYI  I'm getting a response like this.

 

curl https://netmri/api/3.1/config_lists/import?file=test.csv -X POST -H "Content-Type: multipart/form-data" -F "file_name=@/home/user1/test.csv" -k -b tmp.cookie

 

{"error": "general\/unexpected-error", "message": "No such file or directory - test.csv"}

 

Thanks!

Re: Import "Lists" via API?

Authority
Posts: 29
3915     0

Hi Sif,

 

Thank you for your post.  It was very helpful.   I think I'm almost there but i receive the following error:

 

 

[me@server home]$ curl -i -X POST -H "Content-Type: multipart/form-data" -F "file_name=@/home/psctest.csv" https://netmri/api/3.1/config_lists/import?file=psctest.csv -k -b tmp.cookie


HTTP/1.1 100 Continue

HTTP/1.1 400 Bad Request
...
Content-Type: application/json; charset=utf-8

{"error": "general\/unexpected-error", "message": "No such file or directory - psctest.csv"}

 

 

Given the command, where will NetMRI look for the file? 

 

I'm executing this from a linux server.  So will it look at my server's local directory and upload?  Or, is it actually looking on the NetMRI appliance for the file?

 

Sorry, I really have no experience in curl.

 

Thanks for your help. 

Re: Import "Lists" via API?

Adviser
Posts: 470
3915     0

Posted the incorrect one, sorry about that.

 

curl -i -u sbaksh -X POST -H "Content-Type: multipart/form-data" -F "file=@test.csv" https:/netmri/api/3.1/config_lists/import v -k 

And yours should be 

curl -i -X POST -H "Content-Type: multipart/form-data" -F "file_name=@/home/psctest.csv" https://netmri/api/3.1/config_lists/import -k -b tmp.cookie

 

Let me know if that works for you

 

Sif

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

https://sifbaksh.com

Re: Import "Lists" via API?

Authority
Posts: 29
3915     0

Confirmed.  

 

Both of these worked.  I added the overwrite.

curl -i -X POST -H "Content-Type: multipart/form-data" -F "file_name=@/home/psctest.csv" https://netmri/api/3.1/config_lists/import?overwrite_ind=1 -k -b tmp.cookie

 

I believe the form is default so I removed and it continued to operate:

curl -F "file_name=@/home/psctest.csv" https://netmri/api/3.1/config_lists/import?overwrite_ind=1 -k -b tmp.cookie

 

Something to add to the toolbag.

 

Thank you!

Re: Import "Lists" via API?

Authority
Posts: 29
3915     0

Via PERL:

 

use NetMRI::API qw(netmri_api_file);

 

my $import = $client->broker->config_list->import({file=>netmri_api_file 'psctest.csv'});

 

FYI.

Showing results for 
Search instead for 
Did you mean: 

Recommended for You