Send array in fetch body Node

1.6k Views Asked by At

I need to send an array in the body of a fetch request. The value fields has to be an array with lastName and some other values. How do I go about this? I've tried

         let fields = JSON.stringify({ lastName: "test" }); 

but that did not work. I'm trying to do this in node.js. This is the code:

        const params = new URLSearchParams();

        params.append("name", name);
        params.append("email", email);
        params.append("fields", fields);

        fetch(url, {
          headers: Authorization,
          method: "POST",
          body: params,
        })
          .then((e) => {
            console.log(e);
          })

The request itself works fine, it's just fields that isn't picked up.

0

There are 0 best solutions below