Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@crowdfundhq
Last active October 26, 2016 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crowdfundhq/ae875361ca940eef633cf02a4451054d to your computer and use it in GitHub Desktop.
Save crowdfundhq/ae875361ca940eef633cf02a4451054d to your computer and use it in GitHub Desktop.
An example of how to use the CrowdfundHQ API from within your site
<script>
// Enable 'Sessions enabled' in Manage Site > Configuration > Settings > API
// Then use this script in Manage Site > Design > Pages or Scripts to fetch users
document.addEventListener('DOMContentLoaded', function(){
// Define variables
var url = '/api/v1/user/list', result, list, user;
// Do ajax call using hq.js
hq.ajax(url, {
success: function(json) {
// Parse API response
result = JSON.parse(json);
// Parse list as JSON
list = result.data;
// Look up first entry
user = list[0];
// Do something with user
console.log(user);
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment