Reduce the parameters of WordPress CURL

17 viewscurlphpwordpresszoho
0

I am following the Zoho WorkDrive API docs to upload a file.

When I use simple PHP to post via curl:

$folderId = 'xxxx';
$token    = 'xxxx';
$filepath = 'C:\Users\Me\Pictures\test-file.jpg';

$realPath = realpath( $filepath );
$content  = curl_file_create( $realPath );

//the parameters
$postFields = array(
  'filename'            => 'test.jpg',
  'parent_id'           => $folderId,
  'override-name-exist' => 'true',
  'content'             => $content
 );

$curl_url = 'https://workdrive.zoho.com/api/v1/upload';
$curl_var = curl_init();
curl_setopt( $curl_var, CURLOPT_URL, $curl_url );
curl_setopt( $curl_var, CURLOPT_POST, 1 );
curl_setopt( $curl_var, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $curl_var, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $curl_var, CURLOPT_POSTFIELDS, $postFields );
curl_setopt( $curl_var, CURLOPT_HTTPHEADER, array(
  'Authorization: Bearer ' . $token,
  'cache-control: no-cache'
) );
$response = curl_exec( $curl_var );
curl_close( $curl_var );
echo $response;

I can successfully Upload the file.

However when I use WordPress Curl:

$folderId = 'xxxx';
$token    = 'xxxx';
$filepath = 'C:\Users\Me\Pictures\test-file.jpg';
$url      = 'https://workdrive.zoho.com/api/v1/upload';

$realPath = realpath( $filepath );
$content  = curl_file_create( $realPath );

//the parameters
$postFields = array( 
  'filename'            => 'test.jpg',
  'parent_id'           => $folderId,
  'override-name-exist' => 'true',
  'content'             => $content
);

$send = array(
  'headers' => array(
    'cache-control'  => 'no-cache',
    'authorization'  => 'Bearer ' . $token,
  ),
  'body' => $postFields
);

$response = wp_remote_post( $url, $send );
if (
  is_wp_error( $response ) ||
  wp_remote_retrieve_response_code( $response ) != 200 ) {
  error_log( print_r( $response, true ) );
}

return json_decode( wp_remote_retrieve_body( $response ) );

All I keep getting is:

{"errors":[{"id":"F6012","title":"Number of parameters is more than specified"}]}

I have tried adding false on some params, in attempt to reduce them:

...
$send = array(
  ...
  'body' => $postFields,
  /**
   * I found the following in the WP_Http definition,
   * in attempt to reduce parameters.
   * 
   * Adding or removing the following, does not change the result
   */
  'user-agent' => false,
  'sslverify' => false,
  'sslcertificates' => false,
  'redirection' => false,
  '_redirection' => false,
  'decompress' => false,
);
...

My question is, how to reduce the parameters.