on 2024 Oct 30 7:02 AM
Hi experts
I am trying to add a dynamic query to an HTTP GET call URL.
My URL is like https://example.com?$top=2&$select=CustomerID, here the value of top needs to change according to the value passed in header. I have allowed the header in the runtime configuration. I am the adding this value to exchange property in the content modifier before putting the whole query in the query parameters ( I will attach images if this is not clear, sorry, English is not my first language) . However, the call is being made to a URL containing garbage value and I am not sure what is going wrong. I will appreciate any help.
Request clarification before answering.
Hi Resham,
in your case, $top and $select are no headers but query parameters. To fetch their values, you need to implement a GroovyScript as described here: https://help.sap.com/docs/cloud-integration/sap-cloud-integration/access-url-get-parameters-in-scrip...
import com.sap.gateway.ip.core.customdev.util.Message
import java.nio.charset.Charset
import groovy.json.*
// https://help.sap.com/docs/cloud-integration/sap-cloud-integration/access-url-get-parameters-in-scripts
Message processData(Message message) {
String httpQuery = message.getHeader('CamelHttpQuery', String)
// Extract URL Parameters
if (httpQuery) {
Map<String, String> queryParameters = URLDecoder.decode(httpQuery, Charset.defaultCharset().name())
.replace("\$", '')
.tokenize('&')
.collectEntries { it.tokenize('=') }
message.setProperties(queryParameters)
}
return message
}
They are then available as exchange parameters, for example:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
30 | |
21 | |
16 | |
8 | |
7 | |
6 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.