Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

254
Vistas
How to send object in JavaScript With Trello API? (XMLHttpRequest)

I'm new to javaScript. I was able to send some PUT requests, the problem is none of them had me send an object. now I want to send an object to add/change the cover of a card in Trello (change the color alone for example/ add a cover), but in the Trello API, the cover is of type object. how can i do it with XMLHttpRequest?

my normal PUT request (Works, not for object though):

function updateCheckItem(cardId, checkItemId, state) { // state is boolean
   var url = "https://api.trello.com/1/cards/" + cardId + "/checkItem/" + checkItemId + "?key=...&token=...&state=" + state;

   var xhr = new XMLHttpRequest();
   xhr.open("PUT", URL);

   xhr.setRequestHeader("Accept", "application/json");
   xhr.setRequestHeader("Content-Type", "application/json");

   xhr.onreadystatechange = function () {
       if (this.readyState == 4) {
           //do something not relevant
       }
   };

   xhr.send();
}

now, how should I send an object instead of something like the boolean state in the code above?

I've searched and found something about JSON.stringify but didn't work for me/ didn't know exactly how to use it.

my last unworking attempt:

function Cover(cardId) {
   var url = "https://api.trello.com/1/cards/" + cardId + "?key=...&token=...&cover";

   var xhr = new XMLHttpRequest();
   xhr.open("PUT", URL);

   xhr.setRequestHeader("Accept", "application/json");
   xhr.setRequestHeader("Content-Type", "application/json");

   xhr.onreadystatechange = function () {
       if (this.readyState == 4) {
            //do something not relevant
       }
   };

   xhr.send({ "cover": { "color": "pink" } });
}

here are the options: Options for Trello card cover update

here is what a JSON of a Trello card looks like:

{
   "id": "..."
   .
   .
   .
   "cover": {
      "idAttachment": null,
      "color": null,
      "idUploadedBackground": null,
      "size": "normal",
      "brightness": "dark",
      "idPlugin": null
   },
   .
   .
   .
}

and Thank you.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I solved it, if someone finds this and wants the answer, this is it:

function uptadeCardCover(cardId,color,size) {
   var url = "https://api.trello.com/1/cards/" + cardId + "?key=xxxxxx&token=xxxxxxxxx";

   var xhr = new XMLHttpRequest();
   xhr.open("PUT", URL);

   xhr.setRequestHeader("Accept", "application/json");
   xhr.setRequestHeader("Content-Type", "application/json");

   xhr.onreadystatechange = function () {
       if (this.readyState == 4 && this.status == 429) {
           // not relevant
       }
   };

   xhr.send(JSON.stringify({
       "cover": {
           "color": color,
           "size": size
       }
   }));
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda