snipe / snipe-it

A free open source IT asset/license management system
https://snipeitapp.com
GNU Affero General Public License v3.0
11.04k stars 3.18k forks source link

Asset Import Validation Error #13841

Closed TheManTheMythThePanda closed 9 months ago

TheManTheMythThePanda commented 11 months ago

Debug mode

Describe the bug

When importing an Asset CSV file from the console i get this error: The following Errors were encountered. Error: Item: failed validation: {"Asset \"\"":{"model_id":["The model id field is required."],"asset_tag":["The asset tag must be at least 1 characters.","The asset tag must be unique."]}}

The command i run is: php artisan snipeit:import /var/tmp/ssh.csv --verbose

I've read other people having this issue, but i haven't being able to fix the problem for my case. I started with a full .csv file, but i scaled it down to this: Category,Model Name,Asset Tag CGTest,MNTest,KJH90890

I know that there can be a lot more fields used, but the documentation says this is the bare minimum needed, and even this dont work. As you can see, the code says the tag should be unique, but it is. I've also made sure that there are no spaces at the end of the csv file. I have no idea why this wouldn't work, cuz i also didnt get the template asset.csv to work.

Edit: I should by the way remember to mention that it works when using the browser importer. So even tho i could just use the browser importer, in my case it'll be faster and easier to just do it from the console.

Reproduction steps

  1. Go to Snipe-IT directory
  2. Run: php artisan snipeit:import /var/tmp/ssh.csv --verbose

Expected behavior

It should import the asset/assets into Snipe-IT.

Screenshots

No response

Snipe-IT Version

6.2.3 build 11759

Operating System

Ubuntu Server 64-bit

Web Server

Apache

PHP Version

8.2.10-2ubuntu1

Operating System

welcome[bot] commented 11 months ago

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

inietov commented 11 months ago

Have you tried using the --item-type=asset flag? if you run php artisan snipeit:import -help you can see all the options available: image

TheManTheMythThePanda commented 11 months ago

it doesn't seem to change the output. It doesn't fail the asset tag when i rename the csv header to "asset_tag" instead of "Asset Tag". But the same sadly doesnt work with the model id/name.

Krafting commented 9 months ago

Hello, I had the same issue, with the error model_id is required.

I changed Model Name to asset_model in the CSV and it imported correctly. (along with replacing Asset Tag to asset_tag)

I checked this file to get this info: https://github.com/snipe/snipe-it/blob/73ddc0f6693ae5f297d4cfd7187325f1f552e31f/app/Importer/Importer.php#L57

Also, using "model name" in lowercase doesn't work.

I think something might be broken with the field mapping...

TheManTheMythThePanda commented 9 months ago

@Krafting Thank you so much! It is working now as expected. And yea, something is clearly broken with the field mapping haha. But thanks for the fix :D

TheManTheMythThePanda commented 9 months ago

Oops. I forgor to close the issue. The issue is still sorta there, but the workaround worked, ye.