I am trying to implement Indexnow to one of my sites but when I run it I get the response:
{“code”:”InvalidRequestParameters”,”message”:”Invalid request”,”details”:[{“target”:”request.urlList”,”message”:”The urlList field is required.”}]}
This is my (shortened) code:
$urls = array();
if (date('Y-m-d', filemtime('../index.php')) = date('Y-m-d',now())) {array_push($urls,'https://'.$_SERVER['SERVER_NAME'].'/');}
if (date('Y-m-d', filemtime('../credits.php')) = $date('Y-m-d',now())) {array_push($urls,'https://'.$_SERVER['SERVER_NAME'].'/credits');}
$post = array(
'host' => $_SERVER['SERVER_NAME'],
'key' => 'key',
'keylocation' => 'https://'.$_SERVER['SERVER_NAME'].'/key.txt',
'urlList' => $urls
);
unset($urls);
$cp = curl_init('https://api.indexnow.org/indexnow');
curl_setopt ($cp, CURLOPT_HTTPHEADER, Array("application/json; charset=utf-8"));
curl_setopt($cp, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cp, CURLOPT_POST, 1);
curl_setopt($cp, CURLOPT_POSTFIELDS, json_encode($post, JSON_UNESCAPED_UNICODE));
// execute!
$cp_response = curl_exec($cp);
When I do “echo json_encode($post);” I get:
{"host":"www.host.dk","key":"key","keylocation":"https://www.host.dk/key.txt","urlList":["https://www.host.dk/","https://www.host.dk/credits"]}
So what am I missing? Why is it not seeing the urlList array?