google-maps-api-3amp-htmlamp-email

Integrate Google Maps static API with email AMP


We would like to submit a form in email created with AMP4EMAIL to Google Maps Static API and retrieve an image to be displayed in the email according to the form submission.

How can CORS requirement be met for using the API inside AMP email?


Solution

  • There will be more troubles than just not meeting the AMP for Email CORS requirement.

    AMP for Email in general doesn't work very well with most public RESTful APIs like the Google Maps API. Public RESTful APIs usually require the following:

    1. The use of OAuth for authentication
    2. The ability to set various headers in HTTP requests
    3. The ability to use HTTP request methods other than GET and POST

    None of that is possible in AMP for Email.

    On the other hand, public APIs won't respond with the right response headers that meet the AMP CORS requirements.

    The best you can do is to have your own proper XHR endpoint that meets the AMP for Email CORS requirement and proxies the call to the Google Maps API on the server side:

    AMP email -> your AMP for Email XHR endpoint -> Google Maps API