Link to AMP Content

Use the AMP URL API to match URLs to corresponding AMP URLs, and serve the AMP versions instead.

Match URLs to AMP URLs

Request an AMP URL via:

POST https://acceleratedmobilepageurl.googleapis.com/v1/ampUrls:batchGet

List up to 50 URLs as payload in the request body:

{"urls": [
  "https://ampbyexample.com",
  "https://www.example.org/article-without-amp-version"
]}

All requests need to include a development key via X-Authorization header (X-Goog-Api-Key: YOUR-DEVELOPER-KEY). The X-Authorization header value is case sensitive. If you don't have a development key, see Authorization for setup instructions.

Example using curl:

curl -i -s -k -X POST -H "Content-Type: application/json" -H "X-Goog-Api-Key: " -d "{urls: ['https://ampbyexample.com']}" "https://acceleratedmobilepageurl.googleapis.com/v1/ampUrls:batchGet"

Replace URLs with AMP URLs

The batchGet method returns the AMP URL mapping in JSON:

{ 
  "ampUrls": [
    { 
      "originalUrl": "https://ampbyexample.com",
      "ampUrl": "https://ampbyexample.com",
      "cdnAmpUrl": 
         "https://cdn.ampproject.org/c/s/ampbyexample.com"
    }
  ],
  "urlErrors": [
    { 
      "errorCode": "NO_AMP_URL",
      "errorMessage": "AMP URL not found.",
      "originalUrl": "http://www.example.com/no-amp-version.html"
    }
  ]
}

Both the original AMP URL and the one stored in the Google AMP Cache get returned in the response body. We encourage you to use "cdnAmpUrl", instead of "ampUrl", so that your application can have all the benefits of the Google AMP Cache.

Set up redirects

Any time you move the location of AMP files on your server, set up redirects from old locations to new locations. The Google AMP Cache follows redirects when resolving AMP URLs.

If a URL redirects to another valid AMP URL, the Google AMP Cache returns and caches the content of the resolved redirect.