What happens if you just store it to a file?
file_put_contents('path_to_file.pdf', $response->getBody()->getContents());
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I need to download files from an api response. For example:
$url = "https://api-sandbox.xxxxx.co/SG/2.0/reports/waybill?tids=MYKPSxxxxxxxx&h=0";
$response = Http::withToken($token)->get($url);
$data = $response->getBody()->getContents();
$pdf = PDF::loadView('pdf.airbill',compact('data'))->setPaper('A4');
return $pdf->stream('airbill.pdf');
dd($response->getBody()->getContents());
After calling the api, I received null from response $response->json() as the response returns a pdf file directly(not url to download the pdf file). I figured I do not need to use dompdf as well to make another HTML to pdf which was already given from the response.
Based on getContents(), it returns a long list of encoded contents for the PDF so I want to download the pdf and save to my db. Any help is appreciated.
Please or to participate in this conversation.