skip to Main Content

I am using phpmyadmin online database. I have applied client_id and client_secret API manager security and deployed to cloudhub.

Initially, I was able to fetch or update data in database but after deploying to cloudhub and ran in postman got this below error.

Its a put method, with body
{
"source":
{
"CustomerId" : "5",
"Name" : "Sam"

},
"destination":{
    "CustomerId" : "4",
    "Name" : "Jassie"
}

}

This is the query set as a variable.
"SELECT CustomerId,Country FROM Customers WHERE CustomerId IN " ++ "(" ++ "’" ++ payload.source.CustomerId ++ "’" ++ "," ++ "’" ++ payload.destination.CustomerId ++ "’" ++ ")"

{
"message": ""org.mule.weave.v2.exception.UnexpectedFunctionCallTypesException: You called the function ‘++’ with these arguments: n 1: String ("SELECT CustomerId,Country FROM Customers WHERE CustomerId IN (‘")n 2: Null (null)nnBut it expects one of these combinations:n (Array, Array)n (Date, Time)n (Date, LocalTime)n (Date, TimeZone)n (LocalDateTime, TimeZone)n (LocalTime, Date)n (LocalTime, TimeZone)n (Object, Object)n (String, String)n (Time, Date)n (TimeZone, LocalDateTime)n (TimeZone, Date)n (TimeZone, LocalTime)nn6| "SELECT CustomerId,Country FROM Customers WHERE CustomerId IN " ++ "(" ++ "’" ++ payload.source.CustomerId++ "’" ++ "," ++ "’" ++ payload.destination.CustomerId++ "’" ++ ")"n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^nTrace:n at ++ (line: 6, column: 1)n at ++ (line: 6, column: 75)n at ++ (line: 6, column: 103)n at ++ (line: 6, column: 110)n at ++ (line: 6, column: 117)n at ++ (line: 6, column: 124)n at ++ (line: 6, column: 157)n at main (line: 6, column: 164)n" evaluating expression: "%dw 2.0noutput application/javan—n//"(" ++ "’" ++ payload.source.CustomerId++ "’" ++ "," ++ "’" ++ payload.destination.CustomerId++ "’" ++ ")"nn"SELECT CustomerId,Country FROM Customers WHERE CustomerId IN " ++ "(" ++ "’" ++ payload.source.CustomerId++ "’" ++ "," ++ "’" ++ payload.destination.CustomerId++ "’" ++ ")""."
}

2

Answers


  1. From the question, it looks like you are trying to construct query from CustomerId which can be wrapped inside source or destination. The code you have had some null "" values which is not acceptable while concatenating.

    Here is how I would construct the DW by importing string module.

    %dw 2.0
    import unwrap from dw::core::Strings
    output application/java
    ---
    "SELECT CustomerId,Country FROM Customers WHERE CustomerId IN " ++ "(" ++ unwrap(write(payload..CustomerId  , "application/json", {"indent": false}), "")  ++ ")"
    
    

    Here is the sample request and response.
    enter image description here

    Login or Signup to reply.
  2. You can try this…

    %dw 2.0
    output application/json
    ---
    "SELECT CustomerId,Country FROM Customers WHERE CustomerId IN ('" ++ 
    (payload.source.CustomerId as String default "")++ "', '" ++ 
    (payload.destination.CustomerId as String default "") ++ "')"
    

    Using output application/java or application/json depends on that functionality you’ll using this for. The error you are facing is probably due to null value that you are sending. Defaulting it to "" will avoid the dataWeave failure.

    Also, always try to club as many hardcodes string values inside a pair of "" as possible.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search