Aspose cloud api call for excel protect not working

While calling from a php page for protecting a document using curl.
It is not returning protected document. Can anyone help me out.

$bearer_token = 'Authorized Token';
$protectxlsx_headers = array(				
					"accept: application/json",				
					"authorization: Bearer ".$bearer_token,
					"Content-Type: multipart/form-data",
					"x-aspose-client: Containerize.Swagger",
				);
$protectxlsx_data = file_get_contents('path to excel file');
$protectxlsx_ch = curl_init();
curl_setopt($protectxlsx_ch, CURLOPT_URL, 'https://api.aspose.cloud/v3.0/cells/protect?password=ABCD');
curl_setopt($protectxlsx_ch, CURLOPT_POST, true);
curl_setopt($protectxlsx_ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($protectxlsx_ch, CURLOPT_HTTPHEADER, $protectxlsx_headers);
curl_setopt($protectxlsx_ch, CURLOPT_POSTFIELDS, $protectxlsx_data);
$protectxlsx_apiresult = curl_exec($protectxlsx_ch);
url_close($protectxlsx_ch);
$protectxlsx_apiresult_jsondecode = json_decode($protectxlsx_apiresult, true);

@martinhorsley,

We tested the protection API in C# code.
It passed.
Please send us your account email.
We will check the system logs for problem analysis.
And we have created a ticket on our Redmine system about this issue.

@martinhorsley
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSCLOUD-12342

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hello

Everytime i calling API. It is responding with this.

Blockquote

protectxlsx_apiresult_jsondecode=>array(2) {
[“RequestId”]=>
string(36) “1f449060-2119-493b-a518-6ad5ebc10d12”
[“Error”]=>
array(4) {
[“Code”]=>
string(21) “errorInvalidInputData”
[“Message”]=>
string(65) “: Failed to read the request form. Missing content-type boundary.”
[“Description”]=>
string(46) “Operation Failed. The input data is not valid.”
[“DateTime”]=>
string(28) “2023-09-13T09:11:32.9977721Z”
}
}

Blockquote

@martinhorsley,

We found some details based on the request ID from server logs. From the above display, it should be that there is a problem setting multipart/form-data.
Please try to use Aspose.Cells Cloud SDK for PHP to finish your work. And refer to the following code base on Aspose.Cells Cloud SDK for PHP.

We will also do our best to fix your code.

 $instance = new CellsApi(getenv("CellsCloudClientId"),getenv("CellsCloudClientSecret"),"v3.0",getenv("CellsCloudApiBaseUrl"));
 $assemblyTestXlsx = "assemblytest.xlsx";
 $dataSourceXlsx = "datasource.xlsx";
 
 $mapFiles = array ();
 $mapFiles[$assemblyTestXlsx] = CellsApiTestBase::getfullfilename($assemblyTestXlsx);
 $mapFiles[$dataSourceXlsx] = CellsApiTestBase::getfullfilename($dataSourceXlsx);
 
 $request = new PostProtectRequest();
 $request->setFile( $mapFiles);
 $request->setPassword('12345');
 $protectWorkbookRequest = new ProtectWorkbookRequst();
 $request->setProtectWorkbookRequst($protectWorkbookRequest);
 $instance->postProtect($request);

We will also do our best to fix your code.

@martinhorsley,

Please refer to the following code to modify the way you upload files.

 $curl = curl_init();
 $bearer_token = 'your access token';
 $protectxlsx_headers = array(
 "accept: application/json",
 "authorization: Bearer ".$bearer_token,
 "Content-Type: multipart/form-data",
 "x-aspose-client: Containerize.Swagger",
 );
 $data = array('name' => 'Book1.xlsx', 'file' => ' D:\cells.cloud-sdk-php\TestData\Book1.xlsx');
 curl_setopt($curl, CURLOPT_URL, "https://api.aspose.cloud/v3.0/cells/protect? Password=123456");
 curl_setopt($curl, CURLOPT_HTTPHEADER, $protectxlsx_headers);
 curl_setopt($curl, CURLOPT_POST, 1);
 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
 curl_exec($curl);