bbglazer
bbglazer

Reputation: 123

Convert curl command line to php code

I am trying to send this json data via php, and not having the best luck.

curl --header 'Authorization: Bearer <token>' -X POST https://api.site.com --header 'Content-Type: application/json' --data-binary '{"email": "[email protected]", "type": "note", "title": "title", "body": "Note Body"}'

Here's what I have:

     curl_setopt_array($ch = curl_init(), array(
      CURLOPT_HTTPHEADER => array("Authorization: Bearer <token>", "Content-Type: application/json"),
      CURLOPT_URL => "https://api.site.com",
      CURLOPT_POST => true,
      CURLOPT_BINARYTRANSFER => true,
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_POSTFIELDS => array(
        "email" => "[email protected]",
        "type" => "note",
        "title" => "alert",
        "body" => "body",
      ),
      CURLOPT_SAFE_UPLOAD => true,
    ));
    $response = curl_exec($ch);
    curl_close($ch);

Upvotes: 1

Views: 1115

Answers (1)

crazy_ljuba
crazy_ljuba

Reputation: 104

Try like CURLOPT_POSTFIELDS => json_encode( array( "email" => "[email protected]", "type" => "note", "title" => "alert", "body" => "body", )),

Upvotes: 2

Related Questions