How to Map Users from Slack Workspace to Notion Team without Official Integration?

This topic was automatically generated from Slack. You can find the original thread here.

I want to map users from my Slack workspace to the users in my Notion team. There is no official integration between the two services yet but maybe I could to it using their emails, since it’s the same.

Can you suggest some way to facilitate this?

To map users from your Slack workspace to the users in your Notion team using their emails, you can create a Pipedream workflow that: 1. Retrieves the list of users from your Slack workspace. 2. Retrieves the list of users from your Notion team. 3. Matches users based on their email addresses. Here’s a step-by-step guide to achieve this: ### Step 1: Retrieve Users from Slack You can use the Slack API to retrieve the list of users in your workspace. Here’s a Pipedream component to get the list of users from Slack: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { slack: { type: "app", app: "slack", }, }, async run({ steps, $ }) { const response = await axios($, { url: `https://slack.com/api/users.list`, headers: { Authorization: `Bearer ${this.slack.$auth.oauth_access_token}`, }, }); return response.members; }, }); ### Step 2: Retrieve Users from Notion You can use the Notion API to retrieve the list of users in your workspace. Here’s a Pipedream component to get the list of users from Notion: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { notion: { type: "app", app: "notion", }, }, async run({ steps, $ }) { const response = await axios($, { url: `https://api.notion.com/v1/users`, headers: { Authorization: `Bearer ${this.notion.$auth.oauth_access_token}`, "Notion-Version": `2021-08-16`, }, }); return response.results; }, }); ### Step 3: Match Users by Email Finally, you can create a Pipedream component to match users from Slack and Notion based on their email addresses: ``` export default defineComponent({ async run({ steps, $ }) { const slackUsers = steps.slackUsers; const notionUsers = steps.notionUsers; const matchedUsers = slackUsers.filter(slackUser => { return notionUsers.some(notionUser => notionUser.email === slackUser.profile.email); }); return matchedUsers;

How could I handle retrieving “Guest” user details from my workspace?

I want to be able to map them to Slack users by email also

To handle retrieving “Guest” user details from your workspace and map them to Slack users by email, you can follow these steps: 1. Retrieve Guest User Details: This step will depend on where and how your guest user details are stored. If you have an API or a database where these details are stored, you can use a Pipedream component to fetch this data. 2. Map to Slack Users by Email: You can use the Slack “Find User by Email” action to map the guest user details to Slack users. Here’s an example Pipedream workflow that demonstrates how to achieve this: ### Step 1: Retrieve Guest User Details Assuming you have an API endpoint to fetch guest user details, you can use a Pipedream HTTP trigger to fetch this data. import { axios } from "@pipedream/platform"; export default defineComponent({ props: { apiUrl: { type: "string", label: "API URL", description: "The URL of the API to fetch guest user details", }, }, async run({ steps, $ }) { const response = await axios($, { url: this.apiUrl, method: "GET", }); return response.data; }, }); ### Step 2: Map to Slack Users by Email Use the Slack “Find User by Email” action to map the guest user details to Slack users. ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { slack: { type: “app”, app: “slack”, }, email: { type: “string”, label: “Email”, description: “The email address of the guest user”, }, }, async run({ steps, $ }) { const response = await axios($, { url: https://slack.com/api/users.lookupByEmail, method: “GET”, headers: { Authorization: Bearer ${this.slack.$auth.oauth_access_token}, }, params: { email: this.email, }, }); return response.data; }, });

is there an easy way to list or create a database of all my guest users in Notion and get their IDs?

To list or create a database of all your guest users in Notion and get their IDs, you can use the Notion API. Below is an example Pipedream component that lists all users in your Notion workspace and filters out the guest users: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { notion: { type: “app”, app: “notion”, }, }, async run({ steps, $ }) { const response = await axios($, { url: https://api.notion.com/v1/users, headers: { Authorization: Bearer ${this.notion.$auth.oauth_access_token}, “Notion-Version”: 2021-08-16, }, }); // Filter out guest users const guestUsers = response.results.filter(user => user.type === ‘guest’); // Extract user IDs const guestUserIds = guestUsers.map(user => user.id); return guestUserIds; }, });

I thinks there is a problema there, Notion API doesn’t retrieve the guest users…

It seems like you’re encountering an issue with the Notion API not retrieving guest users. The Notion API may have limitations or specific requirements for accessing certain types of users, such as guest users. To better assist you, could you please provide more details on the following: 1. What specific endpoint are you using to retrieve users? 2. Are you receiving any error messages or specific responses from the API? 3. Could you share the relevant part of your code where you’re making the API request? This information will help me understand the issue better and provide a more accurate solution.

in Notion API, how can I iterate all lines and get the User ID from a “Person” property column

To iterate over all rows in a Notion database and extract the User ID from a “Person” property column, you can use the Notion API. Below is a Pipedream component example that demonstrates how to achieve this: 1. Search for the Notion app from the step menu 2. Select the “Retrieve Database Items” action 3. Connect your Notion account 4. Pass the Database ID as a prop 5. Iterate over the results to extract the User ID from the “Person” property column Here’s the example code: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { notion: { type: "app", app: "notion", }, databaseId: { type: "string", label: "Database ID", }, }, async run({ steps, $ }) { const url = `https://api.notion.com/v1/databases/${this.databaseId}/query`; const headers = { Authorization: `Bearer ${this.notion.$auth.oauth_access_token}`, "Notion-Version": "2021-08-16", }; let hasMore = true; let nextCursor = null; const userIds = []; while (hasMore) { const response = await axios($, { url, method: "POST", headers, data: { start_cursor: nextCursor, }, }); const results = response.results; for (const page of results) { const personProperty = page.properties["Person"]; if (personProperty && personProperty.type === "people") { for (const person of personProperty.people) { userIds.push(person.id); } } } hasMore = response.has_more; nextCursor = response.next_cursor; } return userIds; }, }); ### Explanation: - Props: The component accepts two props: notion (for authentication) and databaseId (the ID of the Notion database). - API Request: The component makes a POST request to the Notion API to query the database. - Pagination: It handles pagination by checking the has_more flag and using the next_cursor for subsequent requests. - Extracting User IDs: It iterates