Contents
On this page

Upload Import File - Plugixa Testimonial

POST /plugixatestimonial/v1/import-export/import/validate

Upload a CSV or JSON file: step one of an import. It is parsed and previewed, nothing is imported yet.

Administrators only: the user needs WordPress’s manage_options capability. No plugin capability opens this route.

Note. The file is kept in the uploads folder until Run Import uses it. A file that is never imported is never cleaned up.

Request

POST https://your-site.example/wp-json/plugixatestimonial/v1/import-export/import/validate

Request body

Content type: multipart/form-data

Field Type Required Description
file file Yes A .csv or .json file, 10 MB at most. The extension decides how it is read.

A CSV file needs a header row and at least one data row. A JSON file is either this plugin’s JSON export or a plain array of objects, whose first object’s keys become the columns. See Import and export.

Responses

200 OK. The file was read.

{
  "success": true,
  "message": "",
  "data": {
    "format": "csv",
    "total_rows": 2,
    "columns": [
      "Name",
      "Company",
      "Review",
      "Stars"
    ],
    "preview": [
      [
        "Sarah Johnson",
        "Northwind Studio",
        "Setup took ten minutes and our reviews finally look professional.",
        "5"
      ],
      [
        "Lucas Bernard",
        "Atelier Nord",
        "Clear, fast and friendly support from day one.",
        "4"
      ]
    ],
    "suggested_mapping": {
      "Name": "client_name",
      "Company": "client_company",
      "Review": "testimonial_text",
      "Stars": "rating"
    },
    "file_token": "Qm7Xr2Lp9Tz4Vb8Nc3Kd6Wf1Hg5Js0Ya"
  }
}
Field Type Meaning
data.format string csv or json
data.total_rows integer Data rows in the file
data.columns string[] Column names, in file order
data.preview string[][] The first 10 rows, values as strings
data.suggested_mapping object Column name to target field, for the columns it recognised
data.file_token string Pass it to Run Import

Errors

Status Code When
400 rest_error “No file uploaded”, “Only CSV and JSON files are supported”, “File size must be under 10MB”, “CSV file is empty or has no data rows”, “Invalid JSON file”, “No testimonials found in JSON”, or the JSON shape message.
500 rest_error “Failed to read uploaded file”

Plus the errors every endpoint can return.

Examples

curl -s -X POST "https://your-site.example/wp-json/plugixatestimonial/v1/import-export/import/validate" \
  -u "admin:$WP_APP_PASSWORD" \
  -F "file=@testimonials.csv"
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixatestimonial/v1/import-export/import/validate');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_USERPWD        => 'admin:' . getenv('WP_APP_PASSWORD'),
    CURLOPT_POSTFIELDS     => ['file' => new CURLFile('testimonials.csv', 'text/csv')],
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const form = new FormData();
form.append('file', fileInput.files[0]);
const response = await fetch('https://your-site.example/wp-json/plugixatestimonial/v1/import-export/import/validate', {
  method: 'POST',
  headers: {
    'Authorization': 'Basic ' + btoa(`admin:${process.env.WP_APP_PASSWORD}`),
  },
  body: form,
});
const { data } = await response.json();

Quick Links

Share