I would like to pass some simple PHP variables (such as $name1 and $email1) to the following cURL block (PHP-Curl)
JavaScript
x
CURLOPT_POSTFIELDS =>"{n"email": "percy.jackson@gmail.com",n"name": "Percy Jack",}"
Basically replace:
percy.jackson2290@gmail.com
with$email1
Percy Jack
with$name1
Is this possible? Please help!
Advertisement
Answer
Don’t try to create JSON by hand, create an array and use json_encode()
JavaScript
CURLOPT_POSTFIELDS => json_encode(["email" => $email1, "name" => $name1]),
For the more complex version in the comment:
JavaScript
CURLOPT_POSTFIELDS => json_encode([
"sequence" => 1,
"recipients" => [
"signers" => [
["email" => $email1, "name" => $name1, "recipientId" => "1", "roleName" => "Client"]
],
]
]),
Edited version:
JavaScript
CURLOPT_POSTFIELDS => json_encode([
"emailSubject" => "DocuSignAPI-CompositeTemplates",
"emailBlurb" =>"CompositeTemplatesSample1",
"status" => "sent",
"compositeTemplates"=>
["serverTemplates"=>
["sequence"=>"1",
"templateId"=>"ff32490f-58ab-4e26-a505-b32c863b2398"]],
["inlineTemplates"=>
["sequence"=>"1",
"recipients"=>
["signers"=> [
["email" => $email1, "name" => $name1,"recipientId"=>"1","roleName"=>"Client"]]]]]]),