NGINX Setup for Relaying POST API Body Parameters

Hello,

I’m trying to pass the following simple API call to my NGINX server:

curl --location 'https://latest.testing.ca/inventory/alerts
–header ‘Content-Type: application/json’
–form ‘quanity=“30303”’
–form ‘inventory_num=“686180275612312”’
–form ‘code=“SI”’
–form ‘alert=“none”’

In my NGINX code (see below), I’m trying to use proxy_set_body to capture my POST api body parameters (i.e. quantity, inventory_num, code, alert) and relay them to my backend bubble server. Everything works well with the call except for my api body parameters are not being captured by my nginx server, the values are always empty (i.e. no values for quantity, inventory_num, code, alert) . When I hard code the values in my nginx code, the hard coded values get relayed to my backend bubble server.

What am I doing wrong? Is there another NGINX directive that I should be using instead of proxy_set_body? Or, am I declaring my quantity, inventory_num, code, alert as variables incorrectly (i.e. “$arg_quantity”, “$arg_inventory_num”, “$arg_code”, “$arg_alert”}?

I appreciate any advice!


server {
listen 443 ssl;
server_name latest.testing.ca;

resolver 8.8.8.8;

location /inventory/alerts {

	proxy_pass https://final.testing.ca/version-test/api/1.1/wf/inventory-alerts;

    proxy_method POST;  # Use POST method for alerts
    proxy_ssl_server_name on;  # Ensure SNI is passed during the SSL handshake
    proxy_set_body '{"quantity":"$arg_quantity", "inventory_num":"$arg_inventory_num", "code":"$arg_code", "alert":"$arg_alert"}';
    add_header X-Proxy-Passed "true";
}

}

Your first screenshot show more using parameters than json but your header say the content-type is json… what did you set in API connector?

Hi @Jici,

Thanks for jumping in. On the bubble side, I’m using the following backend workflow to capture the post from the NGINX server back to bubble:

No issues when making the call from Postman to the NGINX Proxy Server and back to Bubble. The only issue is that no POST body parameters are being passed or captured by the NGINX server (i.e. quanity etc).

To see if the problem was the NGINX server itself, I added an echo header to the NGINX code:

add_header My-Json-Payload '{"quantity":"$arg_quantity", "inventory_num":"$arg_inventory_num", "code":"$arg_code", "alert":"testing"}';

This creates a visual response back to postman:

Update, I added in the body parameters as a parameter URL as such: https://latest.testing.ca/inventory/alerts?quantity=500&inventory_num=33033&code=SI&alert=none

And now the values are being pulled in as variables by NGINX, but only if they are in the URL. Now I’m confused and not sure how to access the request body parameters as an NGINX variable. Is there some other way I need to call my request body parameters in NGINX instead of using $arg_quantity etc?

Thank you -