Translate command-line cURL to PHP

312

I have a working cURL request I want to translate to PHP code:

curl \
    -X POST \
    -u live_abcdefg: \
    -d '{
        "recipient": {
            "address": "[email protected]"
        }
    }' \
    https://api.sendwithus.com/api/v1/drip_campaigns/abcdefgh/activate

Here is the PHP code I'm trying:

<?php

$theurl = "https://api.sendwithus.com/api/v1/drip_campaigns/abcdefgh/activate";

$ch = curl_init($theurl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); // -X
curl_setopt($ch, CURLOPT_POSTFIELDS, '{ "recipient": { "address": "[email protected]" } }'); // -d
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'live_abcdefg:'); // -u
$response = curl_exec($ch);

var_dump($response); // prints bool(true)

?>

EDIT: Sendwithus (the app that I'm sending requests to) shows that the second request didn't come through (second recipient [email protected] wasn't saved).
What am I doing wrong?
What can I change in the PHP code to start debugging this issue?

People are also looking for solutions to the problem: php - Is it right to call a component function or its output in view form in yii2?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.