Failed to Parse User File JSON when Importing Users with Management API /api/v2/jobs/users-imports

Overview

When attempting to import users using the Management API endpoint /api/v2/jobs/users-imports with the upsert option, the following error message is encountered:

Failed to parse users’ file JSON when importing users. Make sure it is valid JSON.

This issue does not occur using the Extension User Import/Export feature.

rtaImage (7).jpeg

Cause

Extension User Import/Export:

  • The Extension User Import/Export feature automatically converts JSON files from UTF-16 to UTF-8, which is why the error is not encountered when using this method.

Management API:

  • The Management API does not perform this conversion, so it is necessary to manually ensure the JSON file is in UTF-8 encoding.

Solution

To resolve this issue, follow these steps:

  1. Identify the Encoding Issue

    The error occurs because the JSON file being imported contains a Byte Order Mark (BOM) for UTF-16 encoding. The Management API /api/v2/jobs/users-imports expects the file to be in UTF-8 encoding without a BOM.

  2. Convert the File Encoding

    To fix the encoding issue, the JSON file must be converted from UTF-16 to UTF-8.

  3. Re-attempt the Import

    Now that the file has been converted to the correct encoding, re-attempt the user import using the Management API endpoint /api/v2/jobs/users-imports:

    • Make a POST request to /api/v2/jobs/users-imports with the updated JSON file and the upsert option.