Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3663

PHP cURL for Wordpress REST API gives rest_missing_callback_param

$
0
0

I want to list all the categories for my Wordpress site and get this information via the REST API. I generated the application password, that is what I want to use here. Sadly I don't seem to get this to work, I always get this error:

{"code":"rest_missing_callback_param","message":"Wrong parameter(s): name","data":{"status":400,"params":["name"]}}

This is my PHP code:

<?phpinclude 'db-connect.php';$conn = OpenCon();$conn -> set_charset("utf8");$siteId = $_REQUEST["site-id"];$sqlWebsite = "SELECT setting_value FROM ai_settings WHERE id = ".$siteId;$queryWebsite = mysqli_query($conn, $sqlWebsite);$rowWebsite = mysqli_fetch_row($queryWebsite);$websiteArray = json_decode($rowWebsite[0]);$site_url = "https://" . $websiteArray->url;$username = $websiteArray->user;$applicationPassword = $websiteArray->pass;$categoriesEndpont = $site_url . '/wp-json/wp/v2/categories';$headers = array('Content-Type: application/json','Authorization: Basic ' . base64_encode($username.":".$applicationPassword));$data = array('per_page' => '9999');// get categories$categoriesResponse = curlExecute($categoriesEndpont, $headers, $data);print_r($categoriesResponse);function curlExecute($url, $headers, $data = null){  $ch = curl_init();  curl_setopt($ch, CURLOPT_URL, $url);  curl_setopt($ch, CURLOPT_POST, true);  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  $response = curl_exec($ch);  curl_close($ch);  return $response;}?>

What am I missing? I'm lost... :S Thank you!


Viewing all articles
Browse latest Browse all 3663

Trending Articles