Script integration with Notion. This object handles OAuth authentication and request signing. The entire Notion REST API can be used with the request method.

Example

// list pages which have been shared with the Drafts integration
// API Docs: https://developers.notion.com/reference/post-search
let endpoint = "https://api.notion.com/v1/search"

let notion = Notion.create();
let result = notion.request({
"url": endpoint,
"method": "POST",
"data": {
"filter": {
"value": "page",
"property": "object"
}
}
});

// result has JSON payload
// with page properties
if (result.statusCode == 200) {
alert(`Notion Pages Loaded:

${result.responseText}`)
}
else {
alert(`Notion Error: ${result.statusCode}

${notion.lastError}`);
context.fail();
}

Hierarchy

  • Notion

Constructors

  • Create new instance.

    Parameters

    • Optional identifier: string

    Returns Notion

Properties

lastError?: string

If a function fails, this property will contain the last error as a string message, otherwise it will be undefined.

lastResponse: any

If a function succeeds, this property will contain the last response returned by Notion. The JSON returned by Notion will be parsed to an object and placed in this property. Refer to Notion API documentation for details on the contents of this object based on call made.

version: string

Release version of the Notion API to target. Default is "2022-02-22". If you need capabilities not available in a particular version, you can override the value. See Notion's versioning docs for details.

Methods

  • Execute a request against the Notion API. For successful requests, the HTTPResponse object will contain an object or array or objects decoded from the JSON returned by Notion as appropriate to the request made. Refer to Notion's API documentation for details about the expected parameters and responses. Drafts will handle wrapping the request in the appropriate OAuth authentication flow.

    Parameters

    • settings: {
          data?: {
              [x: string]: string;
          };
          headers?: {
              [x: string]: string;
          };
          method: string;
          parameters?: {
              [x: string]: string;
          };
          url: string;
      }

      an object configuring the request.

      • Optional data?: {
            [x: string]: string;
        }

        A JavaScript object containing data to be encoded into the HTTP body of the request. Refer to API documentation for appropriate information to include.

        • [x: string]: string
      • Optional headers?: {
            [x: string]: string;
        }

        An object contain key-values to be added as custom headers in the request. There is no need to provide authorization headers, Drafts will add those. Drafts will automatically include required authentication and versioning headers.

        • [x: string]: string
      • method: string

        The HTTP method, like "GET", "POST", etc.

      • Optional parameters?: {
            [x: string]: string;
        }

        An object containing key-values to be added to the request as URL parameters.

        • [x: string]: string
      • url: string

        The full URL to the endpoint in the Notion REST API.

    Returns HTTPResponse

  • Creates a new Notion object.

    Parameters

    • identifier: string

      Optional string value used to identify a Notion account. Typically this can be omitted if you only work with one Notion account in Drafts. Each unique identifier used for Notion accounts will share credentials - across both action steps and scripts.

    Returns Notion

Generated using TypeDoc