---
description: >-
  This tutorial shows how flows can be shared in Appmixer either using the API
  or the SDK.
---

# Sharing Flows

## Introduction

Appmixer provides a built-in support for sharing flows with other users. When a user shares their flow, they provide a list of email addresses of other Appmixer users that they want to share their flow with:

![Both Flow Manager and Designer provides Share menu item.](https://3844357853-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LATDgYqVMe0hChW7efU%2F-LmAH_YIL1H4eJt4-LkI%2F-LmAJHzNPmDQjRPD3cIh%2FScreenshot%202019-08-13%20at%2016.10.18.png?alt=media\&token=923bfcaa-933e-4835-8884-c879a8c36b1a)

![Share dialog with a list of users the flow is shared with.](https://3844357853-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LATDgYqVMe0hChW7efU%2F-LmAH_YIL1H4eJt4-LkI%2F-LmAJbkhD60zFeregr6p%2FScreenshot%202019-08-13%20at%2016.11.57.png?alt=media\&token=a707408d-9880-4f96-ab77-46a68a5bcc8b)

When a flow is shared, users from the share list can see the flow in their accounts.

{% hint style="info" %}
Note that the flow is shared in the sense that there's only one instance of the flow in the Appmixer engine. Therefore, if the recipient of the shared flow e.g. starts the flow, the flow appears started also for the owner of the flow and for the other recipients too. If you want to have separate instances, clone the original flow and share each clone with one recipient.
{% endhint %}

## Sharing Flows Using the Appmixer JavaScript SDK

To share a flow using the Appmixer SDK,  update the flow with the special `sharedWith` list. The list contains objects with `email` and `permissions` properties where `email` is the email address of another Appmixer user and `permissions` is a list of permissions. Currently, the following permissions are available:

| Permission | Description                                    |
| ---------- | ---------------------------------------------- |
| `read`     | The user can read the flow but cannot edit it. |
| `start`    | The user can start the flow.                   |
| `stop`     | The user can stop the flow.                    |

{% hint style="info" %}
&#x20;Sharing flows with other users for editing is not yet available.
{% endhint %}

Example:

```javascript
appmixer.api.updateFlow('9089f275-f5a5-4796-ba23-365412c5666e', {
    sharedWith: [{
        email: 'david@client.io',
        permissions: ['read', 'start', 'stop']
    }]
}).then(() => {
    console.log('Flow successfully shared.');
}).catch((err) => {
    console.log('Something went wrong.', err);
});
```

To unshare a flow, simply update the `sharedWith` array with an empty list:

```javascript
appmixer.api.updateFlow('9089f275-f5a5-4796-ba23-365412c5666e', {
    sharedWith: []
}).then(() => {
    console.log('Flow successfully unshared.');
}).catch((err) => {
    console.log('Something went wrong.', err);
});
```

{% hint style="info" %}
Note that the `sharedWith` array is returned from the `appmixer.api.getFlow()` method. However, only the owner can see the list of users they shared the flow with. The recipients of the shared flow only see one item in the list and that's the email address and permissions for themselves.
{% endhint %}

### Define Sharing Options in the Share Dialog

The FlowManager and Designer UI widgets contain menus that allow the user to share their flows. Invoking the share menu item brings up a dialog box that looks like this:

![Share Dialog](https://3844357853-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LATDgYqVMe0hChW7efU%2F-Lu22p-rW88fPlO4CkNj%2F-Lu23XVsGdO_nB5QB3a7%2Fimage.png?alt=media\&token=850fd5ee-c49e-49c9-8d17-477ccb7f37d8)

The Appmixer SDK allows you to configure the sharing options available to the user. For example, you can define that the share dialog will give the user permission to share their flow only for read (and not stop/start) with:

```javascript
appmixer.ui.FlowManager({
  // ... other options ...
  options: {
    sharePermissions: [
      { label: 'Read', value: 'read' }
    ]
  }
});

...

appmixer.ui.Designer({
  // ... other options ...
  options: {
    sharePermissions: [
      { label: 'Read', value: 'read' }
    ]
  }
});
```

You can also define the share types (email, domain, scope):

```javascript
appmixer.ui.FlowManager({
  // ... other options ...
  options: {
    shareTypes: [
      { label: 'Email', value: 'email', placeholder: 'Enter an email address' },
      { label: 'Scope', value: 'scope', placeholder: 'Enter a scope' },
      { label: 'Domain', value: 'domain', placeholder: 'Enter a domain' }
    ],
    sharePermissions: [
      { label: 'Read', value: 'read' }
    ]
  }
});
```

## Sharing Flows Using the Appmixer API

Sharing flows with the Appmixer API follows the same pattern as sharing flows using the Appmixer SDK. To share a flow, update the flow with the `sharedWith` list:

```
curl -XPUT "https://api.appmixer.com/flows/9089f275-f5a5-4796-ba23-365412c5666e" -H "Content-Type: application/json" -d '{ "sharedWith": [{ "email": "david@client.io", "permissions": ["read", "start", "stop"]}] }'
```
