Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

feature: payload to Query String #127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions sample-sharedflows/SF-PayloadToQueryString/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## USAGE

**create flow callout policy in your proxy**

```xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<FlowCallout async="false" continueOnError="false" enabled="true" name="FC-PayloadToQueryString">
<DisplayName>FC-PayloadToQueryString</DisplayName>
<FaultRules/>
<Properties/>
<Parameters>
<Parameter name="SF-PayloadToQueryStrin.fields">["name"]</Parameter>
</Parameters>
<SharedFlowBundle>SF-PayloadToQueryString</SharedFlowBundle>
</FlowCallout>
```

---

## Call the proxy

```sh
curl --location --request POST {{proxyURL}} \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "lama",
"gender": "female",
"age": 26
}'
```


Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Javascript async="false" continueOnError="false" enabled="true" timeLimit="200" name="JS-ExtractPayloadAndAssignQueryString">
<DisplayName>JS-ExtractPayloadAndAssignQueryString</DisplayName>
<Properties/>
<ResourceURL>jsc://JS-ExtractPayloadAndAssignQueryString.js</ResourceURL>
</Javascript>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
if(request.content !== null || request.content !== ''){
try{
var fields = JSON.parse(context.getVariable("SF-PayloadToQueryStrin.fields"));
payload = JSON.parse(request.content);

for(var i in fields){
var field = fields[i];
if(payload[field] !== undefined){
print("[INFO] found key: " + field);
context.setVariable("request.queryparam."+field, payload[field]);
delete payload[field];
}
else{
print("[WARN] didn't find key: " + field);
}
}
}catch(e){
print("[ERROR] Exception Occured:\t" + e);
}
finally{
print("[INFO] Assigning the new payload to the request object");
context.setVariable("request.content", JSON.stringify(payload));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SharedFlow name="default">
<Step>
<Name>JS-ExtractPayloadAndAssignQueryString</Name>
</Step>
</SharedFlow>