0

i am trying to import users to auth0 using "users import bulk api".

curl_setopt_array($curl, [
  CURLOPT_URL => "https://***/api/v2/jobs/users-imports",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"users\"; filename=\"filename.json\"\r\nContent-Type: text/json\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"connection_id\"\r\n\r\n********\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"external_id\"\r\n\r\n******\r\n-----011000010111000001101001--\r\n",
  CURLOPT_HTTPHEADER => [
    "authorization: Bearer ".$token."",
    "content-type: multipart/form-data; boundary=---011000010111000001101001"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

i tried to get the file content with stream_get_contents and file_get_contents.

i always get the same error: {“statusCode”:400," error":“Bad Request”, “message”:“Users file must not be empty.”, “errorCode”:“operation_not_supported”}

  • A raw form post is not what `CURLOPT_POSTFIELDS` are meant to be, hence HTTP 400 (your fault)... "Users file must not be empty" is explicit and means that you're posting nothing at all. – Martin Zeitler Jun 06 '22 at 15:22
  • i followed auth0 documentation https://auth0.com/docs/manage-users/user-migration/bulk-user-imports#request-bulk-user-import i kept the same format – Lahmer Bechir Jun 06 '22 at 15:49
  • Does this answer your question? [How to upload files with POST form-data in PHP?](https://stackoverflow.com/questions/58850246/how-to-upload-files-with-post-form-data-in-php) – Martin Zeitler Jun 06 '22 at 15:51
  • i got the same error – Lahmer Bechir Jun 06 '22 at 16:13

0 Answers0