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
  • 825
  • 2
  • 15
  • 33
  • 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
  • 914,110
  • 126
  • 1,211
  • 1,335
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98