Making POST requests with FormData objects in body

Created on 15 June 2022, over 2 years ago

Hello! Thanks for the very useful module—I've been using it on a couple projects recently.

Currently, I'm working with a third-party API (though one where I could ask their developers for changes if need be) in which filtering is done using a formData object in the body of the request. For example, making a request with searchCriteria: { "SchoolId": 3975 } in the formData filters results to only those with a matching SchoolId.

I'm currently passing those into the body of the requests in my JavaScript front end, like so:

    fetch(url, {
      method: "POST",
      body: formData,
    })

(url is my custom API Proxy's URL.)

Those requests successfully return data, but based on the response I get, the formData isn't being applied, because I continue to see all results from the endpoint, rather than a filtered subset of those results. I can see that the formData object is correctly included when my API Proxy URL is called via my Network tab, but I don't think the proxy URL is passing it over to the third-party API.

Assuming my understanding of the situation is correct, do I need to adjust anything (I suppose in either my custom API Proxy plugin code or in its admin configuration) to make sure the formData gets included? I did come across one example implementation that uses preprocessOutgoingRequestOptions() to make some tweaks to the body, but wasn't exactly sure where to go with that in my case, particularly since I'm not dealing with files like they are.

Any help you can offer would be much appreciated, and let me know if I need to provide any more context. Thanks again!

💬 Support request
Status

Active

Version

2.0

Component

Code

Created by

🇺🇸United States kurttrowbridge

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024