Free Support Forum - aspose.cloud

Add Watermark to Microsoft Word document in PHP using Aspose.Words REST API returns blank response

Using following code to hit watermark API from Aspose Word product family. But getting blank response and I am not able to understand what I am doing wrong. Would appreciate if anybody could help.

$ch = curl_init('https://api.aspose.cloud/v4.0/words/{filename}/watermarks/texts');
        $postRequest = array(
            'name' => $filename
        );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postRequest);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Accept: application/json',
            'Content-Type: application/json',
            'Aauthorization: Bearer '.$access_token
        ));
        $apiResponse = curl_exec($ch);
        curl_close($ch);
        print_r($apiResponse);
        $jsonArrayResponse = json_decode($apiResponse);
        print_r($jsonArrayResponse);

@VastuChetan

I have tested the InsertWatermarkText API using cURL and Aspose.Words Cloud SDK for PHP and unable to notice the reported issue. Please check the sample code for reference. Hopefully, it will help you to accomplish the task.

curl -X POST "https://api.aspose.cloud/v4.0/words/Sections.docx/watermarks/texts?folder=Temp&destFileName=Temp/Sections_Watermark.docx" 
-H "accept: application/json" 
-H "Authorization: Bearer [JWT_Access_Token]" 
-H "Content-Type: application/json" 
-d "{"Text":"Aspose.Words Cloud","RotationAngle":90}"
require_once('D:\xampp\htdocs\aspose-words-cloud-php-master\vendor\autoload.php');

//TODO: Get your ClientId and ClientSecret at https://dashboard.aspose.cloud (free registration is required).

$ClientSecret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$ClientId="xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx";

$wordsApi = new Aspose\Words\WordsApi($ClientId,$ClientSecret);


try {

    $remoteDataFolder = "Temp";
    $localFile = "C:/Temp/Sections.docx";
    $remoteFileName = "Sections.docx";
	
    $outputFileName = "TestWaterMark.docx";

        
	$uploadRequest = new Aspose\Words\Model\Requests\UploadFileRequest($localFile,$remoteDataFolder."/".$remoteFileName,null);
	$wordsApi->uploadFile($uploadRequest);
	

           $requestWatermarkText = new \Aspose\Words\Model\WatermarkText(array(
            "text" => "This is the text",
            "rotation_angle" => 90.0,
        ));
        $request = new Aspose\Words\Model\Requests\InsertWatermarkTextRequest(
            $remoteFileName,
            $requestWatermarkText,
            $remoteDataFolder,
            NULL,
            NULL,
            NULL,
            $remoteDataFolder . "/" . $outputFileName,
            NULL,
            NULL
        );

        $result = $wordsApi->insertWatermarkText($request);
		
	##Download file 
	$request = new Aspose\Words\Model\Requests\DownloadFileRequest($remoteDataFolder."/".$outputFileName,NULL,NULL);
	$result = $wordsApi->downloadFile($request);
	copy($result->getPathName(),"WaterMarkOutput.docx");
	print_r($result);
		
		
    
} catch (Exception $e) {
    echo  "Something went wrong: ",  $e->getMessage(), "\n";
    PHP_EOL;
}