request('POST', 'https://api.cloudconvert.com/v2/capture-website', [ 'headers' => [ 'Authorization' => 'Bearer ' . config('services.cloudconvert.token'), ], 'json' => [ 'url' => $this->bookmark->url, 'output_format' => 'png', 'screen_width' => 1440, 'screen_height' => 900, 'wait_until' => 'networkidle0', 'wait_time' => 100, ], ]); $taskId = json_decode($takeScreenshotJobResponse->getBody()->getContents(), false, 512, JSON_THROW_ON_ERROR)->data->id; // Now wait till the status job is finished $screenshotJobStatusResponse = $retryClient->request('GET', 'https://api.cloudconvert.com/v2/tasks/' . $taskId, [ 'headers' => [ 'Authorization' => 'Bearer ' . config('services.cloudconvert.token'), ], 'query' => [ 'include' => 'payload', ], ]); $finishedCaptureId = json_decode($screenshotJobStatusResponse->getBody()->getContents(), false, 512, JSON_THROW_ON_ERROR)->data->id; // Now we can create a new job to request thst the screenshot is exported to a temporary URL we can download the screenshot from $exportImageJob = $client->request('POST', 'https://api.cloudconvert.com/v2/export/url', [ 'headers' => [ 'Authorization' => 'Bearer ' . config('services.cloudconvert.token'), ], 'json' => [ 'input' => $finishedCaptureId, 'archive_multiple_files' => false, ], ]); $exportImageJobId = json_decode($exportImageJob->getBody()->getContents(), false, 512, JSON_THROW_ON_ERROR)->data->id; // Again, wait till the status of this export job is finished $finalImageUrlResponse = $retryClient->request('GET', 'https://api.cloudconvert.com/v2/tasks/' . $exportImageJobId, [ 'headers' => [ 'Authorization' => 'Bearer ' . config('services.cloudconvert.token'), ], 'query' => [ 'include' => 'payload', ], ]); // Now we can download the screenshot and save it to the storage $finalImageUrl = json_decode($finalImageUrlResponse->getBody()->getContents(), false, 512, JSON_THROW_ON_ERROR)->data->result->files[0]->url; $finalImageUrlContent = $client->request('GET', $finalImageUrl); Storage::disk('public')->put('/assets/img/bookmarks/' . $taskId . '.png', $finalImageUrlContent->getBody()->getContents()); $this->bookmark->screenshot = $taskId; $this->bookmark->save(); } }