use this
return Response::json($response);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
The external api that I'm trying to integrate works so that it always returns http 200 response and errors or success messages are contained in the xml body instead.
Here're the examples of successful and unsuccessful response bodies:
$response = Http::post('http://example.com/myendpoint', $data);
/** Successful request response */
$response->ok(); // Output: true
$response->body();
/*
"<ProcessJobResponse>
<ProcessJobResult>
<Response>
<Status code="200" text="OK" />
</Response>
</ProcessJobResult>
</ProcessJobResponse>"
*/
/** Unsuccessful request response */
$response->ok(); // Output: true
$response->body();
/*
<ProcessJobResponse>
<ProcessJobResult>
<Response>
<Status code="500" text="Import failed on Job: 55 - Object reference not set to an instance of an object." />
</Response>
</ProcessJobResult>
</ProcessJobResponse>
*/
Can't figure out how to structure the response returns in my api implementation correctly in this case. I can convert xml to array, no problem there.
Please or to participate in this conversation.