-
-
Save tfrench15/0b45a79c83c5a21c23e6f1301ef5ed98 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This function calls Segment's Profile API to fetch a user's Traits. Similarly, we can fetch | |
// a user's Event history, Metadata, Account Hierarchies, and more. | |
const axios = require('axios'); | |
exports.handler = function(context, event, callback) { | |
// Initialize an axios client with the base URL of Segment's Profile API and your Segment API token | |
// for Basic Authentication. | |
const profile = axios.create({ | |
baseURL: `https://profiles.segment.com/v1/spaces/${context.spaceId}/collections/users/profiles`, | |
auth: { | |
username: context.token, | |
password: '', | |
} | |
}); | |
// Fetch a user's traits using email as the identifier. To fetch a user's event history, query the `/events` | |
// endpoint. | |
profile | |
.get(`/email:${event.email}/traits`) | |
.then((response) => { | |
return callback(null, response.data.traits); | |
}) | |
.catch((error) => { | |
console.log(error); | |
return callback(error); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment