'How to use Curl to submit URLs İn Bulk With İndexNow API?

You know, with the indexnow api, we can now index pages instantly in bing and yandex search engines. I prepared a file like in the documentation(https://www.indexnow.org/documentation), but I don't know with which command to run it from the terminal.

I will be glad if experienced people can help.

Thanx.



Solution 1:[1]

You could use curl from example below if it still actual.

curl -X POST \
  -H "Content-Type: application/json; charset=utf-8" \
  -d '{"host": "example.org", "key":"my-perfect-key", "urlList": ["https://example.org/page1","https://example.org/page2"]}' \
  https://yandex.com/indexnow

Don't forget to place keyfile in the root of your site.

Solution 2:[2]

<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
//-- ????????? --//
$dlm = "|~|";  // ?????? ???????????
$dlmBreack = "\n"; // ???????????
$dlmCount = "10000";  // ??????????? ?????????? ??????????? ????? ?? ?????
$txtfile = "url.txt"; // ???? ?????? ?????????? ?????? URL-???????
$IndexNowKey = "6352b4ae24df467dbffe0adb9438cd28"; // ???? IndoxNew
$uRoor = "example.com"; // ?????
$uHttps = "https"; // http ??? https
$uEngine = "www.bing.com";  // ???? ???????? ?????? - yandex.com, www.bing.com ??? api.indexnow.org
//-- ????????? --//
$uRLS = "".$uHttps."://$uRoor/"; // ???????? Url ? ?????????? http ??? https
$txtfile = preg_replace("!^s+!m", "", $txtfile); // ???????? ??????? ? ?????? ??????
$txtfile = preg_replace("![\n\r]+\s*[\n\r]+!", "\r\n", $txtfile); // ??????? ?????? ??????
$DoLink = file_get_contents($txtfile);
$Link = explode($dlmBreack, $DoLink, $dlmCount);
 for($in = 0; $in < count($Link); $in++){
$Urls = explode($dlm, $Link[$in]);
$uUrl = $Urls[0]; // ?????? ?? ???????
if ($uUrl!=='') { $BLGe[]="$uUrl"; } // ??????? ?????? ??????
 }
$data = array('host' => "$uRoor", 'key' => "$IndexNowKey", 'keyLocation' => "".$uRLS."".$IndexNowKey.".txt", 'urlList' =>array_reverse(array_reverse($BLGe)));
$data_string = json_encode($data);
$ch = curl_init("https://$uEngine/indexnow");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json; 
charset=utf-8'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, false);
$res = curl_exec($ch);
$result = curl_exec($ch);
$http_code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$res = json_encode($res, JSON_UNESCAPED_UNICODE);
 if ($http_code == 200) { echo "<div class=\"alert alert-success text-center\" role=\"alert\">???? ??????? -$http_code <b>???????????? ? ??????? ?????????? $count URL</b></div><div class=\"alert alert-secondary text-center\" role=\"alert\">???? - <b>$uHost</b>, ?????? - <b>$uEngine</b></div>"; }
 elseif ($http_code == 202) { echo "<div class=\"alert alert-primary text-center\" role=\"alert\">???? ??????? -$http_code <b>???????????? ? ??????? ?????????? $count URL, ????????? ???????? ????? IndexNow</b></div><div class=\"alert alert-secondary text-center\" role=\"alert\">???? - <b>$uHost</b>, ?????? - <b>$uEngine</b></div>"; }
 elseif ($http_code == 400) { echo "<div class=\"alert alert-danger text-center\" role=\"alert\">???? ??????? -$http_code <b>???????? ??????. ???????? ??????</b></div><div class=\"alert alert-secondary text-center\" role=\"alert\">???? - <b>$uHost</b>, ?????? - <b>$uEngine</b></div>"; }
 elseif ($http_code == 403) { echo "<div class=\"alert alert-danger text-center\" role=\"alert\">???? ??????? -$http_code <b>?????????. ???????????????? ???? (????????, ???? ?? ??????, ???? ??????, ?? ???? ??????????? ? ?????)</b></div><div class=\"alert alert-secondary text-center\" role=\"alert\">???? - <b>$uHost</b>, ?????? - <b>$uEngine</b></div>"; }
 elseif ($http_code == 422) { echo "<div class=\"alert alert-danger text-center\" role=\"alert\">???? ??????? -$http_code <b>???????????????? ??????. URL-?????? ?? ??????????? ????? ??? ???? ?? ????????????? ????? ? ?????????</b></div><div class=\"alert alert-secondary text-center\" role=\"alert\">???? - <b>$uHost</b>, ?????? - <b>$uEngine</b></div>"; }
 elseif ($http_code == 429) { echo "<div class=\"alert alert-danger text-center\" role=\"alert\">???? ??????? -$http_code <b>??????? ????? ????????. ????????????? ???????????????? ????</b></div><div class=\"alert alert-secondary text-center\" role=\"alert\">???? - <b>$uHost</b>, ?????? - <b>$uEngine</b></div>"; 
}
 else { echo "<div class=\"alert alert-danger text-center\" role=\"alert\">$http_code -<b> ?????? ???????? ?????? URL</b></div>"; 

?>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nick Kugaevsky
Solution 2 ????????? ????????