How to proxy POST Request in Netlify?

I’m trying to call my API (netlify function hosted in the same team) using POST. At first I use status code 200 for the proxy, but it just returns the request with no response and no x-nf-request-id. Then, I tried to omit the status code, leaving the redirect code only this:

[[redirects]]
  from = "/api/*"
  to = "https://deploy-preview-2--energy-monitoring-backend-itb-ac-id.netlify.app/.netlify/functions/setup-server/:splat"
  force = true
  headers = {Access-Control-Allow-Origin = "*", Access-Control-Allow-Methods = "POST"}

The Location returns the right URL ( x-nf-request-id: aa60936f-5ce8-41d9-962d-97152a19479a-14525254 ) , but after this my POST Request becomes GET Request ( x-nf-request-id: 5c8154ab-6c92-420a-bd18-29a4cde20776-8610475 ), which makes it fails as my API only accepts POST.

If I tried to use status code 307/308 to maintain POST request, Netlify would redirect me to 404 Not Found ( x-nf-request-id: e0c2e38a-f01d-41ec-96e6-67e297111830-10026811 and e0c2e38a-f01d-41ec-96e6-67e297111830-10023464 ).

How to proxy this POST Request? Do I need to use netlify functions? I also need to change the origin so I can send cookies to the API. How?

Site: https://deploy-preview-1--energy-monitoring-itb-ac-id.netlify.app

Hey there, @darkGrimoire :wave:

Welcome to the Netlify Forums. Thanks for writing such a detailed post about this. I have closed the other threads that you opened (here and here) so that we can focus the conversation in one place. This will ensure that individuals to not respond to multiple posts with similar or the same information.

Have you taken a look at our redirects debugging guide as well as our Docs? These would be good places to start if you have not :slight_smile:

Hey @darkGrimoire

Did you find solution to the problem of POST APIs ?

I haven’t found solution yet, and we are undergoing backend migration so I haven’t take a closer look at this issue. The error it gives is Network Error, and I think the problem is in our backend so I’ll try to look into our system first.

1 Like

Hey there, @darkGrimoire :wave:

I just wanted to follow up, as this thread has been a bit quiet recently. Did the error end up being a backend error in your system, or is this still unresolved?

Let us know at your earliest convenience.

it is solved. Actually, I don’t know where the error originates from because after we migrates our backend to azure it suddenly works straight away. Maybe there’s a problem when proxying to netlify-lambda? Well anyway, it works now. Thank you for all of your help!

1 Like

That is great, I am so glad this is resolved for you! :netliconfetti: