i am looking for an example to call data from API request using CURL in php. Currently i am working on vreasy project, where i need to get data from its API. But in vreasy example, they have shown some like this
curl -u "<your-api-key>:" -X GET "https://api.vreasy.com/reservations?status=ENQUIRY&expand=guest&fields=guest/fname,guest/lname,guest/email"
so, my question how can i use this example to work with my PHP code. I want an example on PHP using this method. I am new to this, sorry for that if this question looks like silly.
I am working on wordpress project, where need to data which retrieve from this API into wordpress custom post type.
i have tried something like this.
<?php
echo 'asd';
$api_key = 'your-api-key';
$url = 'https://api.vreasy.com/reservations?status=ENQUIRY&expand=guest&fields=guest/fname,guest/lname,guest/email';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, $api_key . ":"); // Normally you'd put a password after the colon, but you don't need it if you're using an API key
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$response_json = json_decode($response, true);
print_r($response_json);
curl_close($ch);
but there is no response. Thanks