Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
Tiene un problema para obtener información correctamente del lienzo y enviar información a Discord a través de webhook con node-fetch

Así que estoy tratando de enviar datos desde la api de canvas usando un GET y uso esa información y envío un POST desde el mismo punto final a discord usando node fetch. Puedo recibir datos del lienzo sin problemas y registro en la consola para asegurarme de que tengo los datos correctos, pero parece que no puedo obtener ninguna información para discordar. Estoy usando webhooks de discords y no puedo entender dónde me estoy equivocando.

 fetch(url + `courses/${course}/discussion_topics` , { method: "GET", headers : { 'Authorization' : 'Bearer <auth token>', 'Content-Type' : 'application/json' } }) .then(res => res.json()) .then(data => { console.log(data[0].id); console.log(data[0].title); console.log(data[0].message); } ) .then(fetch("https://discord.com/api/webhooks/893327519103746149/<webhooktoken>", { method: "post", headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: {content: 'hello world'} })) .catch(err => console.log(err)) });```
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Como se menciona en el comentario, en caso de que tenga algún error tipográfico o malentendido.

Además, necesita JSON.stringyify su cuerpo.

Por favor, pruebe el siguiente ejemplo:

 fetch(url + `courses/${course}/discussion_topics`, { method: "GET", headers: { Authorization: "Bearer <auth token>", "Content-Type": "application/json", }, }) .then(res => res.json()) .then(data => { console.log(data[0].id); console.log(data[0].title); console.log(data[0].message); }) .then(() => fetch( "https://discord.com/api/webhooks/893327519103746149/<webhooktoken>", { method: "POST", headers: { Accept: "application/json", "Content-Type": "application/json", }, body: JSON.stringify({ username: "Canvas-Bot", content: "hello world", }), } ) .then(res => res.json()) .then(data => { console.log({ data }); }) ) .catch(err => console.log(err));

Otro enfoque sería en async/await. Creo que es más limpio.

 (async function main() { try { const res1 = await fetch(url + `courses/${course}/discussion_topics`, { method: "GET", headers: { Authorization: "Bearer <auth token>", "Content-Type": "application/json", }, }); const data1 = await res1.json(); console.log(data1); const res2 = await fetch( "https://discord.com/api/webhooks/893327519103746149/<webhooktoken>", { method: "POST", headers: { Accept: "application/json", "Content-Type": "application/json", }, body: JSON.stringify({ username: "Canvas-Bot", content: "hello world", }), } ); const data2 = await res2.json(); console.log(data2); } catch (err) { console.log(err); } })();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!