Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Notion

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

Index

Constructors

Properties

Methods

Constructors

constructor

  • new Notion(identifier?: string): Notion
  • Create new instance.

    Parameters

    • Optional identifier: string

    Returns Notion

Properties

Optional lastError

lastError: string

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

lastResponse

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.

Methods

request

  • request(settings: { data?: {}; headers?: {}; method: string; parameters?: {}; url: string }): HTTPResponse
  • 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?: {}; headers?: {}; method: string; parameters?: {}; url: string }

      an object configuring the request.

      • Optional data?: {}

        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?: {}

        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?: {}

        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

Static create

  • create(identifier: string): Notion
  • 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