Hello Shah.
I've just implemented 'url-form-encoded' request for endpoint.
This was not clear for me too. One of the unexpected and undescribed tricks has in 'invoke' !
Here my suggested solution for you (hope this will useful):
(Here is my invoke preparation in gateway script. You can pay attention that I'm not use 'apim' in v10 )
// let's assume your request body have two params
var requestBody = {
'param1': "some_param",
'param2': "another_param"
};
// building new request form body by iteration through all parameters in requst body
var formBody = [];
for (var property in requestBody){
var encodedKey = encodeURIComponent(property);
var encodedValue = encodeURIComponent(properties[property]);
formBody.push(encodedKey + '=' + encodedValue);
}
// join(concate) all parameters by necessary 'ampersand' symbol
formBody = formBody.join('&');
//set necessary header
context.message.header.set('Content-Type','application/x-www-form-urlencoded');
//write body for for context for new invoke
context.message.body.write(formBody);
(And here is invoke defitions):
- invoke:
version: 2.2.0
title: invoke
backend-type: detect
header-control:
type: blocklist
values: []
parameter-control:
type: allowlist
values: []
http-version: HTTP/1.1
timeout: 60
verb: keep
chunked-uploads: false
persistent-connection: true
cache-response: protocol
stop-on-error: []
websocket-upgrade: false
target-url: $(backendUrl)
inject-proxy-headers: false
decode-request-params: false
encode-plus-char: true
graphql-send-type: detect
Thanks,
Sergey
------------------------------
Sergey Paponov
------------------------------
Original Message:
Sent: Mon April 15, 2024 10:01 AM
From: Shah Wajahat
Subject: Content-type application/x-www-form-urlencoded
Hi steve:
I am using message body as a json and write gatewayscript

but i am unable sent data to backend.
kindly help me
------------------------------
Shah Wajahat
Original Message:
Sent: Wed April 10, 2024 05:31 PM
From: Steve Linn
Subject: Content-type application/x-www-form-urlencoded
Hi Shah,
Are you referring to the API UI consumes property? It has a dropdown for appliance/xml and application/json, but you can also specify your x-www-form-urlencoded in that combo entry field. The post from a few years back also referenced was to create a form based post to a backend in GatewayScript. Once you consume that query string like post, if you need to look at it you'll either need to parse it, which will parse it as a binary document, or you can specify buffering: true so the payload will be fully read before the assembly begins.
Regards,
Steve
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
Original Message:
Sent: Fri April 05, 2024 06:28 AM
From: Shah Wajahat
Subject: Content-type application/x-www-form-urlencoded
Hi,
I am consuming an api which content-type is x-www-form-urlencoded and i have check their is no way to define x-www-form-urlencoded
kindly tell me how can i used this type of api.
------------------------------
Shah Wajahat
------------------------------