Skip to content

getUserInfo

This method results in the adapter calling the CRM to retrieve key information about the currently logged in user. This method should return an associative array containing the following keys and values.

Key Value
id The account ID of the user within the CRM. This not the user's personal ID, but that of the parent account.
name The name of the user within the CRM. This will be shown in the Chrome extension to indicate who is currentlyly logged into the CRM.
timezoneName The three-letter timezone identifier of the user.
timezoneOffset The timezone offset of the user, expressed as a positive or negative integer.
platformAdditionalInfo An associative array of additional information about the user in the CRM. See below.
overridingHostname Some CRMs provision unique URLs to each account within their service. For example, to access your account one would use a URL such as https://mycompanydomain.crm.com. The property tells the framework your company's unique URL if there is one.

platformAdditionalInfo

Key Value
companyId The company or account ID of the user within the CRM.
companyName The name of the company or account the user is associated with in the CRM.
companyDomain The domain of the account within the CRM.
async function getUserInfo({ authHeader, additionalInfo }) {
    // ------------------------------------------------------
    // ---TODO.1: Implement API call to retrieve user info---
    // ------------------------------------------------------
    try {
        // API call to get logged in user info
        // const userInfoResponse = await axios.get('https://api.crm.com/user/me', {
        //     headers: {
        //         'Authorization': authHeader
        //     }
        // });
        const mockUserInfoResponse = {
            data: {
                id: 'testUserId',
                name: 'Test User',
                time_zone: 'America/Los_Angeles',
                time_zone_offset: 0
            }
        }

        const id = mockUserInfoResponse.data.id;
        const name = mockUserInfoResponse.data.name;
        const timezoneName = mockUserInfoResponse.data.time_zone ?? ''; // Optional. Whether or not you want to log with regards to the user's timezone
        const timezoneOffset = mockUserInfoResponse.data.time_zone_offset ?? null; // Optional. Whether or not you want to log with regards to the user's timezone. It will need to be converted to a format that CRM platform uses,
        return {
            successful: true,
            platformUserInfo: {
                id,
                name,
                timezoneName,
                timezoneOffset,
                platformAdditionalInfo: {}  // this should save whatever extra info you want to save against the user
            },
            returnMessage: {
                messageType: 'success',
                message: 'Successfully connected to TestCRM.',
                ttl: 3000
            }
        };
    }
    catch (e) {
        return {
            successful: false,
            returnMessage: {
                messageType: 'warning',
                message: 'Failed to get user info.',
                ttl: 3000
            }
        }
    }
async function getUserInfo({ authHeader, hostname }) {
    try {
        const userInfoResponse = await axios.get('https://api.pipedrive.com/v1/users/me', {
            headers: {
                'Authorization': authHeader
            }
        });
        const id = userInfoResponse.data.data.id.toString();
        const name = userInfoResponse.data.data.name;
        const timezoneName = userInfoResponse.data.data.timezone_name;
        const timezoneOffset = userInfoResponse.data.data.timezone_offset;
        return {
            successful: true,
            platformUserInfo: {
                id,
                name,
                timezoneName,
                timezoneOffset,
                platformAdditionalInfo: {
                    companyId: userInfoResponse.data.data.company_id,
                    companyName: userInfoResponse.data.data.company_name,
                    companyDomain: userInfoResponse.data.data.company_domain,
                },
                overridingHostname: hostname == 'temp' ? `${userInfoResponse.data.data.company_domain}.pipedrive.com` : null
            },
            returnMessage: {
                messageType: 'success',
                message: 'Successfully connected to Pipedrive.',
                ttl: 3000
            }
        };
    }
    catch (e) {
        return {
            successful: false,
            returnMessage: {
                messageType: 'warning',
                message: 'Failed to get user info.',
                ttl: 3000
            }
        }
    }
}