Link to AMP Content

  • Utilize the AMP URL API to find corresponding AMP URLs and serve those versions to users.

  • The API allows matching up to 50 URLs at once by sending a POST request with a JSON payload containing the URLs.

  • Include a developer key in the request header for authorization purposes.

  • The API response provides both the original AMP URL and the Google AMP Cache URL; prioritize using the cached version (cdnAmpUrl).

  • Implement redirects for moved AMP files to ensure proper resolution by the Google AMP Cache.

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://www.amp.dev",
  "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://example.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://example.com",
      "ampUrl": "https://example.com",
      "cdnAmpUrl": 
         "https://cdn.ampproject.org/c/s/example.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.