# Connections Module

Import

```
import connections from 'connections';
```

### Methods

[apply(token, options)](https://docs.medable.com/reference#section-apply-token-options-)\
[create(objects, id, targets, options)](https://docs.medable.com/reference#section-create-objects-id-targets-options-)\
[linkTo(objects, id, access, options)](https://docs.medable.com/reference#section-linkto-objects-id-access-options-)\
[list(options)](https://docs.medable.com/reference#section-list-options-)\
[read(tokenOrId, options)](https://docs.medable.com/reference#section-read-tokenorid-options-)\
[delete(tokenOrId, options)](https://docs.medable.com/reference#section-delete-tokenorid-options-)

### apply(token, options)

Applies a connection

**Arguments**

* `token` (String) the unique connection token.
* `options`\
  \- `skipAcl` (Boolean:false) If true, the connection will be applied regardless of the\
  script caller. Normally, only the connection target may apply a connection.

**Returns**

`Connection` (Object)

### create(objects, id, targets, options)

Creates a connection.

**Arguments**

* `objects` (String) the object plural name (eg. accounts)
* `id` (ObjectID) the identifer of the context
* `targets` (Object\[]) a list of connection targets.
  * `_id` (ObjectId:null) the target account identifier. required if email is not set.
  * `email` (String:null) the target account email. required if \_id is not set.
  * `access` (Number) the context access level to impart to the target.
  * `roles` (ObjectId\[]:\[]) a set of context roles to impart to the target.
* `options`
  * `skipAcl` (Boolean:false) if true, share access to the sharing context is not required.
  * `forceAuto` (Boolean:false) automatically create connection, even for objects that normally require acceptance.
  * `skipNotification` (Boolean:false) suppress notifications.
  * `connectionAppKey` (String) attempts to use the original request key, if available. if not available, a key must be passed.
  * `forceAllowConnections` (Boolean:false) if true, will enable connections for an object for which connections are normally disabled.

**Returns**

`Connection` (Object)

### linkTo(objects, id, access, options)

Creates an anonymous, active connection that can be used to access the referenced context via expansion.

**Arguments**

* `objects` (String) the object plural name (eg. accounts)
* `id` (ObjectID) the identifer of the context
* `access` (Number) the level of access to grant the link.
* `options`
  * `skipAcl` (Boolean:false) if true, share access to the sharing context is not required.
  * `expiresInMs` (Integer:null) an optional number of milliseconds before the link expires
  * `expiresAt` (Date:null) optional date when the link will expire. Supersedes expiresInMs.
  * `usesRemaining` (Integer:null) optional number of times the token can be used to load the connection before it expires.
  * `connectionAppKey` (String) attempts to use the original request key, if available. if not available, a key must be passed.
  * `forceAllowConnections` (Boolean:false) if true, will enable connections for an object for which connections are normally disabled.
  * `roles` (ObjectId\[]:\[]) a set of roles to apply to the caller when reading the connection context

**Returns**

`Connection` (Object)

### list(options)

Lists connections for the caller.

**Arguments**

* `options`
  * `paths` (String\[]) limits the result to the specified paths
  * `include` (String\[]) a list of optional paths to include. included paths that are expandable are automatically expanded
  * `expand` (String\[]) a list of paths to expand from referenced ids. Items are expanded with the caller's access level
  * `skip` (Number:0) the number of items to skip. Useful when paging using non-unique sort criteria.
  * `limit` (Number:100) Limit the number of connections to return. Can be between 1 and 1000.
  * `where` (Object) json object describing the where query argument
  * `map` (Object) json object describing the map query argument
  * `sort` (Object) json object describing the sort query argument
  * `group` (Object) json object describing the group query argument
  * `skipAcl` (Boolean:false) if true, connections are not filtered by target/creator.
  * `show` (String) Filters the list. creator only shows invitations by the caller. target only shows invitations to the caller

**Returns**

`Connection[]` (Object)

### read(tokenOrId, options)

Load a connection

**Arguments**

* `tokenOrId` (String/ObjectId) the unique connection token or object id. unless skipAcl is used, loading by token is restricted to the connection target.
* `options`
  * `paths` (String\[]) limits the result to the specified paths
  * `include` (String\[]) a list of optional paths to include. included paths that are expandable are automatically expanded
  * `expand` (String\[]) a list of paths to expand from referenced ids. Items are expanded with the caller's access level
  * `skipAcl` (Boolean:false) when true, any principal is able to read the connection.
  * `skipAccountTest` (Boolean:false) when true, does not demand the calling principal account be verified.

**Returns**

`Connection` (Object)

### delete(tokenOrId, options)

Delete a connection

**Arguments**

* `tokenOrId` (String/ObjectId) the unique connection token or object id.
* `options`
  * `skipAcl` (Boolean:false) when true, any principal is able to delete the connection.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.medable.com/cortex-api/scripting/modules-1/connections-module.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
