Instantly share code, notes, and snippets.

@magician11 /ajax.js
Last active Dec 17, 2018

Embed
What would you like to do?
JavaScript object to query string
const queryParameters = {
actions: 'all',
actions_entities: 'true',
actions_display: 'true',
actions_format: 'list',
actions_limit: '1000',
action_fields: 'all',
action_member: 'true',
action_member_fields: 'all',
action_memberCreator: 'true',
action_memberCreator_fields: 'all',
cards: 'all',
card_fields: 'all',
card_attachments: 'true',
card_attachment_fields: 'all',
card_checklists: 'all',
card_stickers: 'true',
boardStars: 'mine',
labels: 'all',
label_fields: 'all',
labels_limit: '1000',
lists: 'all',
list_fields: 'all',
memberships: 'all',
memberships_member: 'true',
memberships_member_fields: 'all',
members: 'all',
member_fields: 'all',
membersInvited: 'all',
membersInvited_fields: 'all',
checklists: 'all',
checklist_fields: 'all',
organization: 'true',
organization_fields: 'all',
organization_memberships: 'all',
myPrefs: 'true',
fields: 'all'
};
const response = await axios(
`https://trello.com/b/${config.trello.sunbowlBoardId}.json?key=${
config.trello.key
}&token=${config.trello.token}&${objectToQueryString(queryParameters)}`
);
const objectToQueryString = obj =>
Object.keys(obj)
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`)
.join('&');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment