How do I return JSON followed by CURL?

I need to return JSON to the user with a “id” value. I also need to send that “id” to a client’s API.

Usually I have something like
$data = json_encode(array(“id”=“abc123”));
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return $data;

I’m not sure how to send a CURL request after that since I’ve already sent a return. I have read about EVENT_AFTER_SEND, but I’m not sure how to use it. I can’t find any examples either.

Hi yoyoman, can’t you send the cURL before responding to the client?

It cannot. The client’s API version of the “id” is like a foreign key that requires the JSON version of the “id” to already be saved to the database.