Open andersonaas opened 7 years ago
Hi @phpipam !
I am considering adopt the phpipam to management the network in my workplace. I need import some data (like locations) into the tool. This feature has been already implemented? If not, there is a prevision to do so? Also, there is another way to import data, like using API's tools controller for location?
Thanks in advance
Hi, With master branch:
curl -X POST --header "token: <token>" --header "Content-Type: application/json" --data '{"name":"MyName","description":"MyDescr","address":"Postcode or address"}' https://ipam/api/MyApp/tools/locations/
If you have the locations module enabled and a Google geocode API key defined in config.php lat/long will be auto populated.
@phpipam Is this still in your plan to add the option to import a large list of locations from the GUI? I have over 3k locations already with lat/long in csv or xls format and would love the ability to do a bulk import into phpipam.
Thanks
If you need to import a large list of locations from file you can do it with simple while loop, from command line. Something like this:
#!/bin/bash
input="locations.txt"
TOKEN=$(curl -s -X POST --user admin:password http://localhost:8080/api/ipam/user | jq -r '.data.token')
while IFS= read -r line
do
curl -s POST -H "token: $TOKEN" --header "Content-Type: application/json" -d '{"name": '\"$line\"',"description":"Room number","address":""}' http://localhost:8080/api/ipam/tools/locations/
done < "$input"
Or if you have multiple values in one line replace WHILE with this:
while IFS="," read -r value1 value2 value3 value4 remainder; do echo $value1 $value2 $value3 $value4; done < file_name.csv
Extra fields, if any, will appear in 'remainder'
. The shell's default IFS (inter-field-seperator) consisting of comma characters will be used to split each line into its component fields.
The new version of phpipam has a table to include locations, but doesn't have an option to import a lot of locations. Do you think to put this option? Thanks!