Skip to content

Instantly share code, notes, and snippets.

@magician11
Last active June 21, 2022 00:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magician11/c16ae65cacd5cdb793f5f8215c1ef811 to your computer and use it in GitHub Desktop.
Save magician11/c16ae65cacd5cdb793f5f8215c1ef811 to your computer and use it in GitHub Desktop.
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