Search…
Connections
Connections allow for users of your applications to easily share data. They can be created by a user and can extend access to objects from that user to another.
For example, we have User A and User B. User A has a patient file that they'd like to share with User B. However, User B doesn't have any inherent access to this file.
Here User A has the highest level of access to their patient file, Delete access (level 7) because they are the owner of the file. However, User B has no access to the file.
To grant User B access to the file, User A simply needs to create a connection between the patient file and User B and specify the level of access that should be granted.
Here the connection is created and User A specifies that Read access (level 4) should be granted to User B.
Once in place, User B now has access to the patient file and is able to read it.
Through the connection, User B is able to access the file. However, User A has control over User B's access. If User A no longer wants user B to have access, User A simply has to delete the connection.
For all of the access levels, see Access Control in the API documentation.

Accepting a Connections

Retrieve Connections
First find all the connections available to you
1
GET https://api.dev.medable.com/{{your_org_name}}/v2/connections
Copied!
1
{
2
"_id": "552419f585b784bc204e73aa",
3
"access": 2,
4
"context": {
5
"_id": "5519c01aae2fd2b02915c81f",
6
"object": "c_example",
7
"path": "/c_examples/5519c01aae2fd2b02915c81f"
8
},
9
"created": "2015-04-07T17:55:01.000Z",
10
"creator": {
11
"_id": "5516ee2634d8d93428169c0e",
12
"object": "account",
13
"path": "/accounts/5516ee2634d8d93428169c0e"
14
},
15
"expiresAt": "2015-04-14T17:55:01.032Z",
16
"isArchived": false,
17
"object": "connection",
18
"state": 0,
19
"target": {
20
"account": {
21
"_id": "552417e085b784bc204e737c",
22
"object": "account",
23
"path": "/accounts/552417e085b784bc204e737c"
24
},
25
"name": {
26
"first": "Charles",
27
"last": "Best"
28
}
29
},
30
"token": "u0xJRTlDQD8moTuUqeQiCAaFzU1WPdtq"
31
}
Copied!
Accept Connection
Once that token is retrieved, you can accept the connection with a POST utilizing the connection token.
1
POST https://api.dev.medable.com/example/v2/connections/u0xJRTlDQD8moTuUqeQiCAaFzU1WPdtq
Copied!
1
{
2
"_id": "552427adccbc32041380264f",
3
"access": 4,
4
"context": {
5
"_id": "5519c01aae2fd2b02915c81f",
6
"object": "c_example",
7
"path": "/c_examples/5519c01aae2fd2b02915c81f"
8
},
9
"created": "2015-04-07T18:53:33.000Z",
10
"creator": {
11
"_id": "5516ee2634d8d93428169c0e",
12
"object": "account",
13
"path": "/accounts/5516ee2634d8d93428169c0e"
14
},
15
"isArchived": false,
16
"object": "connection",
17
"state": 1,
18
"target": {
19
"account": {
20
"_id": "552417e085b784bc204e737c",
21
"object": "account",
22
"path": "/accounts/552417e085b784bc204e737c"
23
},
24
"email": "[email protected]",
25
"name": {
26
"first": "Charles",
27
"last": "Best"
28
}
29
}
30
}
Copied!

📘Note

The state of the connection is now "1" or "Active"Auto-Accept

Auto Accept

Automatically Applying Connections
In some scenarios, it may be necessary to create connections without the target needing to accept the connection. This is possible if the following apply:
    The context object is not an Account
    The context object does not require connection acceptance
    The target is already a registered user and the account _id is used in the target instead of email
    "auto":true is sent in the connection target
To configure your object to not require connection acceptance, when creating your object or editing your object settings, be sure that Require Connection Accept is unchecked.
Optionally you can uncheck Send Connection Notifications to prevent notifications from going out when connections are created as well.
Automatically applying a connection is then very much like creating a connection like above but with "auto":true added to the target.HTTP
1
POST https://api.dev.medable.com/example/v2/c_prescriptions/576967021d0c03a53cd79fd7/connections
Copied!
Request Body
1
{
2
"targets":[
3
{
4
"object":"account",
5
"_id": "552417e085b784bc204e737c",
6
"access":4,
7
"auto":true
8
}
9
]
10
}
Copied!
JSON Response
1
{
2
"data": [
3
{
4
"_id": "576967441d0c03a53cd7a028",
5
"access": 4,
6
"context": {
7
"_id": "576967021d0c03a53cd79fd7",
8
"object": "c_prescription",
9
"path": "/c_prescriptions/576967021d0c03a53cd79fd7"
10
},
11
"contextSource": null,
12
"created": "2016-06-21T16:11:48.800Z",
13
"creator": {
14
"_id": "575f58281d0c03a53ccc3ac6",
15
"object": "account",
16
"path": "/accounts/575f58281d0c03a53ccc3ac6"
17
},
18
"expiresAt": "2016-06-28T16:11:48.802Z",
19
"object": "connection",
20
"state": 1,
21
"target": {
22
"account": {
23
"_id": "552417e085b784bc204e737c",
24
"object": "account",
25
"path": "/accounts/552417e085b784bc204e737c"
26
}
27
}
28
}
29
],
30
"hasMore": false,
31
"object": "list"
32
}
Copied!

📘Note

The connection is immediately created in state "1" or "Active" without any acceptance needed.
For more details on the connection object, it's properties, and available API routes, see Apply Connection

Creating a Connection

To create a connection you need
    1.
    The context: An object instance you'd like to share
    2.
    The targets: A target user or team of users you'd like to extend access to
A connection can have multiple targets, so an array of targets is sent when creating the connection. A target takes the form of:JSON
1
{
2
"object":"account",
3
"email":"[email protected]",
4
"name":{
5
"first":"Frederick",
6
"last":"Banting"
7
},
8
"access":4
9
}
Copied!
For an individual target if you have only an email address. In cases when you only have the account id, you can also pass in:JSON
1
{
2
"object": "account",
3
"_id": "575f58281d0c03a53ccc3fd3",
4
"access":4
5
}
Copied!
    When inviting an individual, object will always be "account".
    Then, either email or _id of the account must be sent. email is useful for inviting individuals when the account _id is either not known or if the individual does not yet have a user account. If a user with that username exists in the org, the user account will automatically be used. If using email you can optionally specify the name as illustrated above. This can be useful in connection notification templates. For example, you can send personalized emails with the recipient's name included in the message.
    access is the level of context access you are granting to the target.
Creating a connection is a matter of calling a route with the following pattern:HTTP
1
POST https://api.dev.medable.com/{{your_org_code}}/v2/{{object_name}}/{{object_id}}/connections
Copied!
Where your_org_code is the org code you specified when signing up. object_name is the plural name of the object you are creating a connection to and object_id is the _id of the object instance that you are creating a connection to.
Here's an example on a c_prescription instance:HTTP
1
POST https://api.dev.medable.com/example/v2/c_prescriptions/576967021d0c03a53cd79fd7/connections
Copied!
Request Body
1
{
2
"targets":[
3
{
4
"object":"account",
5
"email":"[email protected]",
6
"name":{
7
"first":"Frederick",
8
"last":"Banting"
9
},
10
"access":4
11
}
12
]
13
}
Copied!
JSON Response
1
{
2
"data": [
3
{
4
"_id": "576967441d0c03a53cd7a028",
5
"access": 4,
6
"context": {
7
"_id": "576967021d0c03a53cd79fd7",
8
"object": "c_prescription",
9
"path": "/c_prescriptions/576967021d0c03a53cd79fd7"
10
},
11
"contextSource": null,
12
"created": "2016-06-21T16:11:48.800Z",
13
"creator": {
14
"_id": "575f58281d0c03a53ccc3ac6",
15
"object": "account",
16
"path": "/accounts/575f58281d0c03a53ccc3ac6"
17
},
18
"expiresAt": "2016-06-28T16:11:48.802Z",
19
"object": "connection",
20
"state": 0,
21
"target": {
22
"email": "[email protected]",
23
"name": {
24
"first": "Frederick",
25
"last": "Banting"
26
}
27
}
28
}
29
],
30
"hasMore": false,
31
"object": "list"
32
}
Copied!
The above created a connection with [email protected] to the c_prescription instance with _id 5519c01aae2fd2b02915c81f. But notice that the state of the connection is "0" of "Pending". This is because it has not yet been accepted by Mr. Banting.
Mr. Banting would then receive an email notification at [email protected] notifying him that John Smith at NewHealthCo would like to share a Prescription file. Once Fred registers as a user, he can then accept or decline the connection. If accepted, Mr. Banting would have Read access to the c_prescription (level 4).
Last modified 1mo ago