javascriptgoogle-apps-scripttrello

Creating a trello card from the apps script sidebar results in status code 500


I wanted to implement the trello api into a sidebar so my team can create tickets in a more manageable way than texting.

I built the sidebar & functionality using vscode; which is also where I tested everything.

There were no problems until I moved everything to my apps script project; any submission results in Response: 500.

This is the code I wrote to create the card:

function createCard() {
    name = document.querySelector('#n').value;
    request = document.querySelector('#r').value;
    details = document.querySelector('#d').value;
    priority = document.querySelector('#high');
    idLabels = (priority.checked) ? '62a685a6ea88a630d3da970f' : '62a685b2b835cd665d8ba4ac';
    fetch(`https://api.trello.com/1/cards?
        key=${key}&
        token=${token}&
        idList=${idList}&
        name=${name} - ${request}&
        desc=${details}&
        idLabels=${idLabels}`, {
            method: 'POST'
            }).then(response => {
                console.log(`Response: ${response.status} ${response.statusText}`);
                return response.text();
            }).then(text => console.log(text))
                .catch(error => console.error(error));
}

I couldn't find anything that would prevent me from using an api in the sidebar.

This is the closest thing I could find to my current problem is right here:

Google Apps Script to Create Confluence Page -- Results in Status Code 500

but this isn't using sidebar (if that even matters)


Solution

  • Modification points:

    When these points are reflected in your script, how about the following modification?

    From:

    fetch(`https://api.trello.com/1/cards?
        key=${key}&
        token=${token}&
        idList=${idList}&
        name=${name} - ${request}&
        desc=${details}&
        idLabels=${idLabels}`, {
            method: 'POST'
            }).then(response => {
    

    To:

    const encodedName = encodeURIComponent(`${name} - ${request}`);
    const url = `https:\/\/api.trello.com\/1\/cards?key=${key}&token=${token}&idList=${idList}&name=${encodedName}&desc=${details}&idLabels=${idLabels}`;
    fetch(url, { method: 'POST' }).then(response => {
    

    Note:

    Reference: