1.2.0 • Published 3 years ago

@dengorbachev/coda-js-client v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

coda-js-client

CodaJsClient - JavaScript client for coda-js-client

Introduction The Coda API is a RESTful API that lets you programmatically interact with Coda docs: List and search Coda docs Create new docs and copy existing ones Share and publish docs Discover pages, tables, formulas, and controls * Read, insert, upsert, update, and delete rows Version 1 of the API will be supported until at least January 15, 2021. As we update and release newer versions of the API, we reserve the right to remove older APIs and functionality with a 3-month deprecation notice. We will post about such changes as well as announce new features in the Developers Central section of our Community, and update the API updates doc. # Getting Started Our Getting Started Guide helps you learn the basic of working with the API and shows a few ways you can use it. Check it out, and learn how to: - Read data from Coda tables and write back to them - Build a one-way sync from one Coda doc to another - Automate reminders - Sync your Google Calendar to Coda # Using the API Coda's REST API is designed to be straightforward to use. You can use the language and platform of your choice to make requests. To get a feel for the API, you can also use a tool like Postman or Insomnia. ## API Endpoint This API uses a base path of https://coda.io/apis/v1. ## Resource IDs and Links Each resource instance retrieved via the API has the following fields: - id: The resource's immutable ID, which can be used to refer to it within its context - type: The type of resource, useful for identifying it in a heterogenous collection of results - href: A fully qualified URI that can be used to refer to and get the latest details on the resource Most resources can be queried by their name or ID. We recommend sticking with IDs where possible, as names are fragile and prone to being changed by your doc's users. ### List Endpoints Endpoints supporting listing of resources have the following fields: - items: An array containing the listed resources, limited by the limit or pageToken query parameters - nextPageLink: If more results are available, an API link to the next page of results - nextPageToken: If more results are available, a page token that can be passed into the pageToken query parameter The maximum page size may change at any time, and may be different for different endpoints. Please do not rely on it for any behavior of your application. If you pass a limit parameter that is larger than our maximum allowed limit, we will only return as many results as our maximum limit. You should look for the presence of the nextPageToken on the response to see if there are more results available, rather than relying on a result set that matches your provided limit. To fetch a subsequent page of results, pass the pageToken parameter. Set this parameter to the value given to you as the nextPageToken in a page response. If no value is provided, there are no more results available. You only need to pass the pageToken to get the next page of results, you don't need to pass any of the parameters from your original request, as they are all implied by the pageToken. Any other parameters provided alongside a pageToken will be ignored. ### Doc IDs While most object IDs will have to be discovered via the API, you may find yourself frequently wanting to get the ID of a specific Coda doc. Here's a handy tool that will extract it for you. (See if you can find the pattern!) <fieldset style=\"margin: 0px 25px 25px 25px; display: inline;\"> Doc ID Extractor <input type=\"text\" id=\"de_docUrl\" placeholder=\"Paste in a Coda doc URL\" style=\"width: 250px; padding: 8px; margin-right: 20px;\" /> Your doc ID is:    <input id=\"de_docId\" readonly=\"true\" style=\"width: 150px; padding: 8px; font-family: monospace; border: 1px dashed gray;\" /> (() => { const docUrl = document.getElementById('de_docUrl'); const docId = document.getElementById('de_docId'); docUrl.addEventListener('input', () => { docId.value = (docUrl.value.match(/_d(\w-+)/) || [])1 || ''; }); docId.addEventListener('mousedown', () => docId.select()); docId.addEventListener('click', () => docId.select()); })(); ## Rate Limiting The Coda API sets a reasonable limit on the number of requests that can be made per minute. Once this limit is reached, calls to the API will start returning errors with an HTTP status code of 429. If you find yourself hitting rate limits and would like your individual rate to be raised, please contact us at help+api@coda.io. ## Consistency While edits made in Coda are shared with other collaborators in real-time, it can take a few seconds for them to become available via the API. You may also notice that changes made via the API, such as updating a row, are not immediate. These endpoints all return an HTTP 202 status code, instead of a standard 200, indicating that the edit has been accepted and queued for processing. This generally takes a few seconds, and the edit may fail if invalid. Each such edit will return a requestId in the response, and you can pass this requestId to the #getMutationStatus endpoint to find out if it has been applied. ## Volatile Formulas Coda exposes a number of \"volatile\" formulas, as as Today(), Now(), and User(). When used in a live Coda doc, these formulas affect what's visible in realtime, tailored to the current user. Such formulas behave differently with the API. Time-based values may only be current to the last edit made to the doc. User-based values may be blank or invalid. ## Free and Paid Workspaces We make the Coda API available to all of our users free of charge, in both free and paid workspaces. However, API usage is subject to the role of the user associated with the API token in the workspace applicable to each API request. What this means is: - For the #createDoc endpoint specifically, the owner of the API token must be a Doc Maker (or Admin) in the workspace. If the \"Any member can create docs\" option in enabled in the workspace settings, they can be an Editor and will get auto-promoted to Doc Maker upon using this endpoint. Lastly, if in addition, the API key owner matches the \"Approved email domains\" setting, they will be auto-added to the workspace and promoted to Doc Maker upon using this endpoint This behavior applies to the API as well as any integrations that may use it, such as Zapier. ## Examples To help you get started, this documentation provides code examples in Python, Unix shell, and Google Apps Script. These examples are based on a simple doc that looks something like this: npm.io ### Python examples These examples use Python 3.6+. If you don't already have the requests module, use pip or easy_install to get it. ### Shell examples The shell examples are intended to be run in a Unix shell. If you're on Windows, you will need to install WSL. These examples use the standard cURL utility to pull from the API, and then process it with jq to extract and format example output. If you don't already have it, you can either install it or run the command without it to see the raw JSON output. ### Google Apps Script examples npm.io Google Apps Script makes it easy to write code in a JavaScript-like syntax and easily access many Google products with built-in libraries. You can set up your scripts to run periodically, which makes it a good environment for writing tools without maintaining your own server. Coda provides a library for Google Apps Script. To use it, go into Resources -> Libraries... and enter the following library ID: 15IQuWOk8MqT50FDWomh57UqWGH23gjsWVWYFms3ton6L-UHmefYHS9Vl. If you want to see the library's source code, it's available here. Google provides autocomplete for API functions as well as generated docs. You can access these docs via the Libraries dialog by clicking on the library name. Required parameters that would be included in the URL path are positional arguments in each of these functions, followed by the request body, if applicable. All remaining parameters can be specified in the options object. ## OpenAPI/Swagger Spec In an effort to standardize our API and make it accessible, we offer an OpenAPI 3.0 specification: - OpenAPI 3.0 spec - YAML - OpenAPI 3.0 spec - JSON ### Swagger 2.0 We also offer a downgraded Swagger 2.0 version of our specification. This may be useful for a number of tools that haven't yet been adapted to OpenAPI 3.0. Here are the links: - Swagger 2.0 spec - YAML - Swagger 2.0 spec - JSON #### Postman collection To get started with prototyping the API quickly in Postman, you can use one of links above to import the Coda API into a collection. You'll then need to set the appropriate header and environment variables. ## Client libraries We do not currently support client libraries apart from Google Apps Script. To work with the Coda API, you can either use standard network libraries for your language, or use the appropriate Swagger Generator tool to auto-generate Coda API client libraries for your language of choice. We do not provide any guarantees that these autogenerated libraries are compatible with our API (e.g., some libraries may not work with Bearer authentication). ### OpenAPI 3.0 Swagger Generator 3 (that link takes you to the docs for the generator API) can generate client libraries for these languages. It's relatively new and thus only has support for a limited set of languages at this time. ### Swagger 2.0 Swagger Generator takes in a legacy Swagger 2.0 specification, but can generate client libraries for more languages. You can also use local CLI tools to generate these libraries. ### Third-party client libraries Some members of our amazing community have written libraries to work with our API. These aren't officially supported by Coda, but are listed here for convenience. (Please let us know if you've written a library and would like to have it included here.) - PHP by Daniel Stieber - Node-RED by Mori Sugimoto - NodeJS by Parker McMullin - Ruby by Carlos Muñoz at Getro - Python by Mikhail Beliansky

This SDK is automatically generated by the Swagger Codegen project:

  • API version: 1.2.0
  • Package version: 1.2.0
  • Build package: io.swagger.codegen.v3.generators.javascript.JavaScriptClientCodegen For more information, please visit https://coda.io

Installation

For Node.js

npm

To publish the library as a npm, please follow the procedure in "Publishing npm packages".

Then install it via:

npm install coda-js-client --save

git

If the library is hosted at a git repository, e.g. https://github.com/GIT_USER_ID/GIT_REPO_ID then install it via:

    npm install GIT_USER_ID/GIT_REPO_ID --save

For browser

The library also works in the browser environment via npm and browserify. After following the above steps with Node.js and installing browserify with npm install -g browserify, perform the following (assuming main.js is your entry file):

browserify main.js > bundle.js

Then include bundle.js in the HTML pages.

Webpack Configuration

Using Webpack you may encounter the following error: "Module not found: Error: Cannot resolve module", most certainly you should disable AMD loader. Add/merge the following section to your webpack config:

module: {
  rules: [
    {
      parser: {
        amd: false
      }
    }
  ]
}

Getting Started

Please follow the installation instruction and execute the following JS code:

var CodaJsClient = require('coda-js-client');
var defaultClient = CodaJsClient.ApiClient.instance;


var api = new CodaJsClient.AccountApi()
api.whoami().then(function(data) {
  console.log('API called successfully. Returned data: ' + data);
}, function(error) {
  console.error(error);
});

Documentation for API Endpoints

All URIs are relative to https://coda.io/apis/v1

ClassMethodHTTP requestDescription
CodaJsClient.AccountApiwhoamiGET /whoamiGet user info
CodaJsClient.AnalyticsApilistDocAnalyticsGET /analytics/docsList doc analytics
CodaJsClient.ColumnsApigetColumnGET /docs/{docId}/tables/{tableIdOrName}/columns/{columnIdOrName}Get a column
CodaJsClient.ColumnsApilistColumnsGET /docs/{docId}/tables/{tableIdOrName}/columnsList columns
CodaJsClient.ControlsApigetControlGET /docs/{docId}/controls/{controlIdOrName}Get a control
CodaJsClient.ControlsApilistControlsGET /docs/{docId}/controlsList controls
CodaJsClient.DocsApicreateDocPOST /docsCreate doc
CodaJsClient.DocsApideleteDocDELETE /docs/{docId}Delete doc
CodaJsClient.DocsApigetDocGET /docs/{docId}Get info about a doc
CodaJsClient.DocsApilistDocsGET /docsList available docs
CodaJsClient.FormulasApigetFormulaGET /docs/{docId}/formulas/{formulaIdOrName}Get a formula
CodaJsClient.FormulasApilistFormulasGET /docs/{docId}/formulasList formulas
CodaJsClient.MiscellaneousApigetMutationStatusGET /mutationStatus/{requestId}Get mutation status
CodaJsClient.MiscellaneousApiresolveBrowserLinkGET /resolveBrowserLinkResolve browser link
CodaJsClient.PacksApiaddPackPermissionPOST /packs/{packId}/permissionsAdd a permission for Pack
CodaJsClient.PacksApicreatePackPOST /packsCreate Pack
CodaJsClient.PacksApideletePackPermissionDELETE /packs/{packId}/permissions/{permissionId}Delete a permission for Pack
CodaJsClient.PacksApigetPackGET /packs/{packId}Get a single Pack
CodaJsClient.PacksApigetPackPermissionsGET /packs/{packId}/permissionsList permissions for a Pack
CodaJsClient.PacksApilistPacksGET /packsList Packs
CodaJsClient.PacksApipackAssetUploadCompletePOST /packs/{packId}/assets/{packAssetId}/assetType/{packAssetType}/uploadCompletePack asset upload complete
CodaJsClient.PacksApipackVersionUploadCompletePOST /packs/{packId}/versions/{packVersion}/uploadCompletePack version upload complete
CodaJsClient.PacksApiregisterPackVersionPOST /packs/{packId}/versions/{packVersion}/registerRegister Pack version
CodaJsClient.PacksApisetPackLiveVersionPUT /packs/{packId}/liveVersionSet live version for Pack
CodaJsClient.PacksApiupdatePackPATCH /packs/{packId}Update Pack
CodaJsClient.PacksApiuploadPackAssetPOST /packs/{packId}/uploadAssetUpload a Pack asset.
CodaJsClient.PagesApigetPageGET /docs/{docId}/pages/{pageIdOrName}Get a page
CodaJsClient.PagesApilistPagesGET /docs/{docId}/pagesList pages
CodaJsClient.PagesApiupdatePagePUT /docs/{docId}/pages/{pageIdOrName}Update a page
CodaJsClient.PermissionsApiaddPermissionPOST /docs/{docId}/acl/permissionsAdd permission
CodaJsClient.PermissionsApideletePermissionDELETE /docs/{docId}/acl/permissions/{permissionId}Delete permission
CodaJsClient.PermissionsApigetPermissionsGET /docs/{docId}/acl/permissionsList permissions
CodaJsClient.PermissionsApigetSharingMetadataGET /docs/{docId}/acl/metadataGet sharing metadata
CodaJsClient.PublishingApilistCategoriesGET /categoriesGet doc categories
CodaJsClient.PublishingApipublishDocPUT /docs/{docId}/publishPublish doc
CodaJsClient.PublishingApiunpublishDocDELETE /docs/{docId}/publishUnpublish doc
CodaJsClient.RowsApideleteRowDELETE /docs/{docId}/tables/{tableIdOrName}/rows/{rowIdOrName}Delete row
CodaJsClient.RowsApideleteRowsDELETE /docs/{docId}/tables/{tableIdOrName}/rowsDelete multiple rows
CodaJsClient.RowsApigetRowGET /docs/{docId}/tables/{tableIdOrName}/rows/{rowIdOrName}Get a row
CodaJsClient.RowsApilistRowsGET /docs/{docId}/tables/{tableIdOrName}/rowsList table rows
CodaJsClient.RowsApipushButtonPOST /docs/{docId}/tables/{tableIdOrName}/rows/{rowIdOrName}/buttons/{columnIdOrName}Push a button
CodaJsClient.RowsApiupdateRowPUT /docs/{docId}/tables/{tableIdOrName}/rows/{rowIdOrName}Update row
CodaJsClient.RowsApiupsertRowsPOST /docs/{docId}/tables/{tableIdOrName}/rowsInsert/upsert rows
CodaJsClient.TablesApigetTableGET /docs/{docId}/tables/{tableIdOrName}Get a table
CodaJsClient.TablesApilistTablesGET /docs/{docId}/tablesList tables
CodaJsClient.WorkspacesApichangeUserRolePOST /workspaces/{workspaceId}/users/roleUpdates user role
CodaJsClient.WorkspacesApilistWorkspaceMembersGET /workspaces/{workspaceId}/usersList workspace users
CodaJsClient.WorkspacesApilistWorkspaceRoleActivityGET /workspaces/{workspaceId}/rolesList workspace roles

Documentation for Models

Documentation for Authorization

Bearer