Skip to main content
Question

Cannot make a POST request in figma plugin

  • July 2, 2022
  • 1 reply
  • 1514 views

Pierre4

Hi there 🙂

I am trying to execute a POST request.
I already succeed with GET request with fetch method (from typescript lib) but I tried a lot of alternatives (axios, node-fetch) to make a POST request without succeed.

So I come back to the basics from the Figma documentation and trying to do my request like that:

var request = new XMLHttpRequest()
  request.open('POST', url)
  request.responseType = 'text'
  request.setRequestHeader('Content-Type', 'application/json')
  request.setRequestHeader('Authorization', 'Bearer XXX')
  request.setRequestHeader('Access-Control-Allow-Origin', '*')

  request.onload = () => {
    console.log("request.response  " + request.response)
    window.parent.postMessage({ pluginMessage: request.response }, '*')
  };
  request.send()

I have this error:

Uncaught (in promise) TypeError: XMLHttpRequest is not a constructor

I am building my Figma plugin with webpack and typescript

Do you have any ideas? Thanks in advance 🙂

This topic has been closed for replies.

1 reply

Vincent_Huss
  • Active Member
  • 29 replies
  • February 11, 2024

I would also love to hear about that if you found a solution, or if anyone knows…


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings