Platform primitives /Functions /

Functions API reference

This page provides a full reference of the Netlify Functions API.

# Netlify-specific Context object

The Context object exposes the following properties:

  • account: an object containing Netlify team account information with the following property:

    • id: unique ID of the team that the site and function belong to.
  • cookies: a simplified interface for reading and storing cookies:

    • cookies.get(name): reads a cookie with a given name from the incoming request.

    • cookies.set(options): sets a cookie on the outgoing response, using the same format as the options value in the CookieStore.set web standard.

    • cookies.delete(name) or cookies.delete(options): adds an instruction to the outgoing response for the client to delete a cookie. Following the CookieStore.delete web standard, accepts a string representing the name of the cookie, or an options object.

      Setting cookies across subdomains only works for custom domains

      netlify.app is listed in the Mozilla Foundation’s Public Suffix List, which prevents setting cookies across subdomains. You can only set a cookie for all subdomains if your site uses a custom domain instead of yoursitename.netlify.app.

  • deploy: an object containing Netlify deploy information with the following property:

    • context: the context of the deploy that the function belongs to.
    • id: unique ID of the deploy that the function belongs to.
    • published: a boolean that indicates whether or not the function belongs to the current published deploy.
  • geo: an object containing geolocation data for the client with the following properties:

    • city: name of the city.
    • country:
      • code: ISO 3166 code for the country.
      • name: name of the country.
    • latitude: latitude of the location.
    • longitude: longitude of the location.
    • subdivision:
      • code: ISO 3166 code for the country subdivision.
      • name: name of the country subdivision.
    • timezone: timezone of the location.
    • postalCode: postal (zip) code of the location. We support all regional formats, so the format will vary.
  • ip: a string containing the client IP address.

  • params: object containing the parameters set for the function’s path in the configuration object and the values they receive from the incoming request URL. For example, for a function configured to run at /pets/:name, the params value for a request to /pets/boo will be {"name":"boo"}. To access the query string, use request.url instead.

  • requestId: a string containing the Netlify request ID; for example, 01FDWR77JMF2DA1CHF5YA6H07C.

  • server: an object containing server metadata with the following property:

    • region: the region code where the deployment is running; for example, us-east-1.
  • site: an object containing Netlify site metadata with the following properties:

    • id: unique ID for the site; for example, 1d01c0c0-4554-4747-93b8-34ce3448ab95.
    • name: name of the site, its Netlify subdomain; for example, petsof.
    • url: URL representing the main address to your site. It can be either a Netlify subdomain or your own custom domain if you set one; for example, https://petsof.netlify.app or https://www.petsofnetlify.com.

# Netlify global object

The Netlify global object exposes the following properties:

  • context: the Netlify-specific context object.

    This property is scope-dependent

    The context object is only available when Netlify.context is accessed from within the scope of a function handler or one of its child scopes. If accessed from somewhere else, like the global scope, it returns null.

  • env: an object providing access to environment variables with the following properties:

    • delete(name): in the context of the invocation, deletes an environment variable with a given name.
    • get(name): returns the string value of an environment variable with a given name; if the environment variable is not defined, undefined is returned.
    • has(name): returns a boolean value containing true if an environment variable with a given name exists, and false otherwise.
    • set(name, value): in the context of the invocation, sets an environment variable with a given name and value.
    • toObject(): returns a plain object containing all the environment variables and their values.