0

I want to have this body:

{
 "name": "sales_support",
 "description": "The sales support team",
 "parentOrgUnitPath": "/corp/support",
 }

In a PHP curl post request.

How do I add the variables into this line properly?

CURLOPT_POSTFIELDS => '{ "name":"' .$createOUname '","description":"' .$description '","parentOrgUnitPath":"'.$parentOUpath'"},

I have tried it like this but then I get this error:

Parse error: syntax error, unexpected ''","description":"'' (T_CONSTANT_ENCAPSED_STRING), expecting ')' 

What did I do wrong in my code? I cant get hold of how to resolve this

Y_Lakdime
  • 793
  • 2
  • 11
  • 27
  • 1
    don't write json string by hand, that's why there's `json_encode` function in the first place – Kevin Nov 15 '19 at 09:39

1 Answers1

0

Create array with variables,and send json_encode() data to CURLOPT_POSTFIELDS

$postFields = array(
    "name"  =>  $createOUname,
    "description"   =>  $description,
    "parentOrgUnitPath" =>  $parentOUpath
)

And then

CURLOPT_POSTFIELDS => json_encode($postFields),
Quentin
  • 857,932
  • 118
  • 1,152
  • 1,264
Anant Kumar Singh
  • 68,309
  • 10
  • 50
  • 94