You would need to create your own API to do this, then call the sitecore API from within.
Something like this should work:
Controller
namespace YourNameSpace.Controllers
{
public class YourController : SitecoreController
{
public ActionResult TriggerIndexRebuild(string indexName, string token)
{
bool success=false;
// code to confirm token against config
try
{
IndexCustodian.FullRebuild(ContentSearchManager.GetIndex(indexName), true);
IndexCustodian.RebuildAll();
success=true;
}
catch(Exception ex)
{
// log the exception
}
return Json(success, JsonRequestBehavior.AllowGet);
}
}
}
Class to register route
namespace YourNameSpace
{
public class RegisterCustomRoute
{
public virtual void Process(PipelineArgs args)
{
Register();
}
public static void Register()
{
RouteTable.Routes.MapRoute("SearchReport", "api/sitecore/triggerindexrebuild/{indexName}/{token}", new { controller = "Your", action = "TriggerIndexRebuild" });
}
}
}
Config to register route
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<initialize>
<processor
type="YourNameSpace.RegisterCustomRoute,YourNameSpace"
patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeRoutes, Sitecore.Mvc']"
/>
</initialize>
</pipelines>
</sitecore>
</configuration>
Once setup, you should then just be able to call:
https://your-sitecore-instance/api/sitecore/triggerindexrebuild/sitecore-web-index/xxxx-xxxx-xxxx
Sitecore Reference here:
https://doc.sitecore.com/xp/en/developers/103/platform-administration-and-architecture/rebuild-search-indexes.html