Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jbowman99's avatar

curl post request and return value

Hello,

I have an API that is making a Post Request to another API, when the data is received an ID is created and needs to be returned to the API for further work. Post request looks like this:

$content = $image_node;

        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($content));

        $json_response = curl_exec($curl);

        curl_close($curl);

        $response = json_decode($json_response, true);
        $node->field_relate_media_node[] = $response;

on the other end:

return drupal_json($node->nid);

back on the laravel side all i am getting back is "true" not quite sure how to return the proper value.

0 likes
1 reply
jbowman99's avatar
jbowman99
OP
Best Answer
Level 7

adding

curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);

helped me return a value in case this ever comes up for any one else.

Please or to participate in this conversation.