I would like so send post parameter via curl. I tried this:
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(
array(
"content" => "Hi",
"message_type" => "outgoing",
"content_type" => "input_select",
"content_attributes" => '{ "items": [{ "title": "Option1", "value": "Option 1" }, { "title": "Option2", "value": "Option 2" }]}',
"private" => false
)
));
But this way does not work. If works like this:
curl_setopt($ch, CURLOPT_POSTFIELDS,
'{
"content": "Hi",
"message_type" : "outgoing",
"content_type": "input_select",
"content_attributes": {
"items": [
{ "title": "Option1", "value": "Option1" },
{ "title": "Option2", "value": "Option2" }
]
},
"private":false
}'
);
Would it be also possible to do it like the way with array (my first try). If yes, where is my mistake?
http_build_querycreates a URL query string format. If you want to create JSON out of your existing data object, then that is of course a case forjson_encode.curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array("content"=>"Hi","message_type"=>"outgoing","content_type"=>"input_select","content_attributes" =>["items"=>[[ "title" =>"Option1", "value" =>"Option 1"],[ "title" =>"Option2", "value": "Option 2"]]],"private" => false)));