Good afternoon, I need your support. I'm trying to make a bash script to notify Google that my sitemap has an update: example link that google gives
this is the script I'm trying to use:
#!/bin/bash
API_KEY='apikey'
SITE_URL="https://test.com"
SITEMAPS=('google_news' 'sitemap')
API_URL="https://searchconsole.googleapis.com/webmasters/v3/sites"
echo "=== PING Sitemaps ==="
DESKTOP=""
for i in "${SITEMAPS[@]}"
do
echo "*** GOOGLE APIS ($i) ***"
URL="https://searchconsole.googleapis.com/webmasters/v3/sites/https://test.com/sitemaps/https://test.com/sitemaps/$i.xml?key=$API_KEY"
echo "URL:$URL"
curl --request PUT \
'https://searchconsole.googleapis.com/webmasters/v3/sites/https%3A%2F%2Ftest.com/sitemaps/https%3A%2F%2Ftest.com%2Fsitemaps%2Fsitemap.xml?key=$API_KEY' \
--header 'Authorization: Bearer $API_KEY' \
--header 'Accept: application/json' \
--compressed
echo "*** BING PING ($i) ***"
URL="https://www.bing.com/ping?sitemap=$SITE_URL/sitemaps/$i.xml"
echo " URL: $i.xml"
curl -s -I -A "$DESKTOP" $URL && echo " - Exitoso" || echo " - Error -"
done
but I get this error:
{
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"errors": [
{
"message": "Invalid Credentials",
"domain": "global",
"reason": "authError",
"location": "Authorization",
"locationType": "header"
}
],
"status": "UNAUTHENTICATED"
}
}
Can someone guide me how to solve it, thanks in advance