cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to add dynamic query parameter from header in HTTP GET call in SAP CPI

resham_naaz
Explorer
0 Kudos
824

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.

Accepted Solutions (0)

Answers (1)

Answers (1)

kevin_albrecht
Explorer
0 Kudos

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:

image.png

image.png