> ## Documentation Index
> Fetch the complete documentation index at: https://developer.box.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Slack Integration Mapping

export const Link = ({href, children, className, ...props}) => {
  const localizedHref = href;
  return <a href={localizedHref} className={className} {...props}>
      {children}
    </a>;
};

Use the `POST integration_mappings/slack/:integration_mapping_id`
call to create a mapping. To make it work,
you need `box_item` and `partner_item` parameters,
which refer to a Box folder and a Slack channel, respectively.

<Info>
  Remember that before the mapping can be created,
  this service account must be set as a co-owner
  role on the folder that is being mapped.
  If you encounter any errors, see the <Link href="/guides/integration-mappings/slack-mappings/troubleshooting">troubleshooting guide</Link>.
</Info>

<CodeGroup>
  ```sh cURL theme={null}
  curl -X -L POST "https://api.box.com/2.0/integration_mappings/slack" \
       -H "authorization: Bearer <ACCESS_TOKEN>" \
       -H 'content-type: application/json' \
       -d '{
            "partner_item": {
                "id": "C987654321",
                "type": "channel",
                "slack_workspace_id": "T5555555"
            },
            "box_item": {
                "id": "123456789",
                "type": "folder"
            }
        }'
  ```

  ```typescript Node/TypeScript v10 theme={null}
  await userClient.integrationMappings.createSlackIntegrationMapping({
    partnerItem: new IntegrationMappingPartnerItemSlack({
      id: slackPartnerItemId,
      slackOrgId: slackOrgId,
    }),
    boxItem: new IntegrationMappingBoxItemSlack({ id: folder.id }),
  } satisfies IntegrationMappingSlackCreateRequest);
  ```

  ```python Python v10 theme={null}
  user_client.integration_mappings.create_slack_integration_mapping(
      IntegrationMappingPartnerItemSlack(
          id=slack_partner_item_id, slack_org_id=slack_org_id
      ),
      IntegrationMappingBoxItemSlack(id=folder.id),
  )
  ```

  ```cs .NET v10 theme={null}
  await userClient.IntegrationMappings.CreateSlackIntegrationMappingAsync(requestBody: new IntegrationMappingSlackCreateRequest(partnerItem: new IntegrationMappingPartnerItemSlack(id: slackPartnerItemId) { SlackOrgId = slackOrgId }, boxItem: new IntegrationMappingBoxItemSlack(id: folder.Id)));
  ```

  ```swift Swift v10 theme={null}
  try await userClient.integrationMappings.createSlackIntegrationMapping(requestBody: IntegrationMappingSlackCreateRequest(partnerItem: IntegrationMappingPartnerItemSlack(id: slackPartnerItemId, slackOrgId: slackOrgId), boxItem: IntegrationMappingBoxItemSlack(id: folder.id)))
  ```

  ```java Java v10 theme={null}
  userClient.getIntegrationMappings().createSlackIntegrationMapping(new IntegrationMappingSlackCreateRequest(new IntegrationMappingPartnerItemSlack.Builder(slackPartnerItemId).slackOrgId(slackOrgId).build(), new IntegrationMappingBoxItemSlack(folder.getId())))
  ```

  ```javascript Node v4 theme={null}
  const mapping = await client.integrationMappings.createSlackIntegrationMapping({
  	partner_item: {
  		type: 'channel',
  		id: 'C12378991223',
  		slack_org_id: 'E1234567'
  	},
  	box_item: {
  		id: '12345',
  		type: 'folder',
  	}
  });
  console.log(
      `Slack integration mapping with id ${mapping.id} was created`
  );
  ```
</CodeGroup>

You can provide options that change the default settings for the
created mapping. For example setting `is_access_management_disabled` to
`true` will disable collaboration management. Slack channel members will
not become collaborators on the channel folder and no shared links will
be created for channels with 1000+ members.

## Create Slack Integration Mapping with Box SDK

Use Box SDK to automatically create the Integration Mapping,
including a co-owner collaboration of the
service account on the Slack channel - Box folder mapping.
To do so, use this script:

```js theme={null}
const BoxSDK = require('box-node-sdk');
const axios = require('axios');

const integrationMappingsApiUrl = 'https://api.box.com/2.0/integration_mappings/slack'
const boxFolderId = 'PASTE YOUR FOLDER ID HERE';
const slackChannelId = 'PASTE YOUR CHANNEL ID HERE';
const slackOrgId = 'PASTE YOUR SLACK ORG ID HERE (CHANGE TO WORKSPACE ID IF NECESSARY)';
const developerToken = 'PASTE YOUR DEVELOPER TOKEN HERE';

let serviceAccountId = '<PLACEHOLDER>';

const client = BoxSDK.getBasicClient(developerToken);

async function postIntegrationMappingSlack(){
    return axios.post(integrationMappingsApiUrl, {
        partner_item: {
            id: slackChannelId,
            slack_org_id: slackOrgId, // change slack_org_id to slack_workspace_id if Box for Slack is installed on the workspace level
            type: "channel"
        },
        box_item: {
            id: boxFolderId,
            type: "folder"
        }
    }, {
        headers: {
            'Authorization': `Bearer ${developerToken}`
        }
    });
}

function isPlaceholder(str){
    return str === '<PLACEHOLDER>';
}

async function addCoowner(serviceAccountId, folderId){
    try {
        await client.collaborations.createWithUserID(serviceAccountId, folderId, 'co-owner')
    } catch (error){
        if(error.response.body.code === 'user_already_collaborator'){
            console.log('Service account already collaborated in the co-owner role.')
        } else {
            throw error;
        }
    }
}

async function logServiceAccountId() {
    try {
        await postIntegrationMappingSlack();
    } catch (error) {
        console.log(`Replace the value of serviceAccountId with: ${error.response.data.context_info.service_account_id} and re-run the script.`)
    }
}

async function createSlackIntegrationMapping() {
    if(isPlaceholder(serviceAccountId)){
        await logServiceAccountId();
    } else {
        await addCoowner(serviceAccountId, boxFolderId);
        await postIntegrationMappingSlack();
    }
}

module.exports = { createSlackIntegrationMapping }
```

<Note>
  Make sure to replace `PLACEHOLDER` with the logged value of
  `serviceAccountId`.
</Note>
