API "Filetype not allowed"

CMS 4.0.7
I have data to upload to a dataset from an outside API.
In Postman, I have the auth token working and am trying to get the dataset import CSV working.
I have the dataset number, column ID and file name identified and set in the body. My headers currently have Content-type = text/csv, Accept = application/json.
The error coming back is:
“files”: [
{
“name”: “1722544703-2271”,
“size”: 1210,
“type”: “text/csv”,
“error”: “Filetype not allowed”
}
]
}
My final goal is to have this in Powershell, but once I have Postman working, I can export to Powershell and clean up the script.
Also,
Do I need the column IDs of each column that I’m replacing or just the first one? I currently have all defined in the body.

The POST /dataset/import/{dataSetId} API expects a csv file as a multipart file upload, so you’d expect something like this in Postman:

curl --location 'http://dataset/import/{dataSetId}' \
--header 'Authorization: Bearer xxx' \
--form 'files=@"/path/to/file"' \
--form 'csvImport_{dataSetColumnId}="0"'

All of them, missing columns would be empty after the import if omitted.

CMS 4.0.7
I have data to upload to a dataset from an outside API.
In Postman, I have the auth token working and am trying to get the dataset import CSV working.
I have the dataset number, column ID and file name identified and set in the body. My headers currently have Content-type = text/csv, Accept = application/json.
The error coming back is:
“files”: [
{
“name”: “1722544703-2271”,
“size”: 1210,
“type”: “text/csv”,
“error”: “Filetype not allowed”
}
]
}
My final goal is to have this in Powershell, but once I have Postman working, I can export to Powershell and clean up the script.
Also,
Do I need the column IDs of each column that I’m replacing or just the first one? I currently have all defined in the body.

If I export the postman as curl, this is the redacted string:

curl --location 'http://xibo addr/api/dataset/import/40' \
--header 'Content-Type: application/csv' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer token \
--header 'Cookie: PHPSESSID= cookie' \
--form 'Files=@"/C:/software/ETD-import/ETD-dataset-import.csv"' \
--form 'csvImport_210="1"' \
--form 'csvImport_211="2"' \
--form 'csvImport_212="3"' \
--form 'csvImport_213="4"' \
--form 'csvImport_214="5"' \
--form 'csvImport_215="6"' \
--form 'overwrite="1"' \
--form 'ignorefirstrow="1"'

If I change or omit the content-type, the error is the same, just shows the content type that I submitted.
And, currently the scope on the auth is blank. Should it have write:all or similar?

I would expect your content type to be Content-Type: multipart/form-data;boundary=SOME_BOUNDARY, which should be automatically generated for you by postman (although I don’t know how that translates into CURL).

@Nadz please can you help with a working example of CSV import to DataSet via the API?

Even with the default multipart/Form-data, the error is the same:

 "name": "1723137444-734",
            "size": 0,
            "type": "multipart/form-data; boundary=--------------------------664407322770268537387157",
            "error": "Filetype not allowed"

How to Import a CSV File into a DataSet via the Xibo API using Postman:

This guide will walk you through the process of setting up a dataset and then importing data from a CSV file using Postman. We’ll use a specific example with three columns: EmployeeNumber, Name, and Age.

Step 1: Set Up the Dataset:

  1. Create a New DataSet, or select an existing one where you want to import the data.
  2. Add Three Columns to your DataSet:
    • EmployeeNumber (Number)
    • Name (String)
    • Age (Number)

Step 2: Create a CSV File with the following content:
image

Step 3: Ensure that you have correctly configured Postman with the necessary API token and other authorization details.

Step 4: Open Postman and Select the Import CSV API endpoint.

Step 5: Go to Params Tab and enter the DataSet ID:

Step 6: Headers: You can leave the default values as they are:

Step 7: Configure the Body:

  1. Go to the Body tab.
  2. Select form-data as the body type (So we can easily upload the CSV file).
  3. Enter the following key-value pairs:
    i. files: Select File and upload the CSV file you want to import.
    ii. csvImport_{dataSetColumnId}: Replace {dataSetColumnId} with the column ID from your DataSet. This is required for mapping the CSV columns to the DataSet columns.
    iii. overwrite: Set this to 1 if you want to erase all existing content in the DataSet before the import. Otherwise, set it to 0.
    iv. ignorefirstrow: Set to 1 if your CSV file includes headers, which should be ignored.
    v. Your Body should look like this:

Step 8: Once everything is set up, click the Send button in Postman to execute the API call. If the request is successful, you should receive a confirmation response indicating the data was imported successfully as shown below.


Here’s the cURL Command for Reference
If you prefer to use cURL directly, here’s the equivalent command for the setup you just worked through:

curl --location 'http://localhost/api/dataset/import/16' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
--header 'Cookie: PHPSESSID=YOUR_SESSION_ID' \
--form 'files=@"/C:/Users/MyUsername/Downloads/dataset.csv"' \
--form 'csvImport_25="1"' \
--form 'csvImport_26="2"' \
--form 'csvImport_27="3"' \
--form 'overwrite="0"' \
--form 'ignorefirstrow="1"'

Replace YOUR_ACCESS_TOKEN and YOUR_SESSION_ID with your actual token and session ID before running the command.

Exactly the same. The default content-type is multipart/form-data, not application/x-www-form-urlencoded. Even with the change, it errors out.
CSV:

"messageCount","malicious","spam","graymail","bec","scam"
"12171","1","114","5051","1","3"

postman CURL:

curl --location 'http://server fqdn/api/dataset/import/40' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: Bearer token \
--header 'Cookie: PHPSESSID=cookie \
--form 'Files=@"/C:/software/ETD-import/ETD-dataset-import.csv"' \
--form 'csvImport_210="1"' \
--form 'csvImport_211="2"' \
--form 'csvImport_212="3"' \
--form 'csvImport_213="4"' \
--form 'csvImport_214="5"' \
--form 'csvImport_215="6"' \
--form 'overwrite="1"' \
--form 'ignorefirstrow="1"'

result:

{"files":[{"name":"1723581434-7599","size":0,"type":"application\/x-www-form-urlencoded","error":"Filetype not allowed"}]}

Any ideas on how to fix this?

I upgraded to 4.10. The new error is

Xibo\Helper\BlueImpUploadHandler::getFileName(): Argument #1 ($name) must be of type string, null given, called in C:\xibo\lib\Helper\BlueImpUploadHandler.php on line 328