mirror issue in request body and headers ou can adjust your code to properly send the CSV file using wp_remote_post()
The csv_file
parameter is set to a CURLFile
object, which represents the file to be uploaded. This should correctly include the CSV file in the request body.
// Set up the request body
$request_body = array(
'csv_file' => new CURLFile($csv_file_path, 'text/csv', $file_name.'.csv'),
'filename' => $file_name,
'website' => $site_url,
);
// Set up the request headers
$request_headers = array(
'Authorization' => 'Bearer ' . $doobert_api_token_value,
);
// Set up the request args
$request_args = array(
'headers' => $request_headers,
'body' => $request_body,
);
// Send the request
$response = wp_remote_post($curlurl, $request_args);
// Check for errors
if (is_wp_error($response)) {
$error_message = $response->get_error_message();
echo "Error: $error_message";
} else {
// Handle response
$response_code = wp_remote_retrieve_response_code($response);
$response_body = wp_remote_retrieve_body($response);
echo "Response Code: $response_code\n";
echo "Response Body: $response_body\n";
}