0

I'm trying to wrap my head around this. I have a multidimensional JSON array. I need to make an API request with PHP cURL. I did find curl_setopt_array in the manual but I still need help. How do I achieve this?

array

$json = array(
"user" => $email,
"attributes" => array(
"name" => "Janet User",
"password" => $email_password,
"delivery_forward" => false
)
);

cURL

//
// Get cURL resource
//
$curli = curl_init();
//
// Set some options - we are passing in a useragent too here
//
curl_setopt_array($curli, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => "https://horizon.opensrs.net:55443/X-Username:".$connection_details['reseller_username']."/X-Signature:".$connection_details['api_key']."/",
CURLOPT_USERAGENT => 'some company'
]);
//
// Send the request & save response to $resp
//
$respc = curl_exec($curli);
//header('Content-Type: application/json');
$c_response =json_decode($respc, true);
print_r($c_response);
Grogu
  • 2,097
  • 15
  • 36
  • Could you please provide what request you trying to make? If you can make curl request in terminal. You easily could convert it to php code using https://incarnate.github.io/curl-to-php/ – Urmat Zhenaliev Dec 10 '20 at 04:04
  • @UrmatZhenaliev : could you mark this as duplicate of https://stackoverflow.com/questions/11079135/how-to-post-json-data-with-php-curl#15643608 I found my answer – Grogu Dec 11 '20 at 00:46

1 Answers1

0

Try this:

curl_setopt($curli, CURLOPT_POSTFIELDS, $json);
   // withContent-Type:multipart/form-data;
   

Good luck

Taha Lamti
  • 74
  • 1
  • 8