-2

I try to replace the token with a variable so that i dont need to hardcode the token but it seems I cant do it.Token on HTTP Request and this is the output from postman `"You called the function '+' with these arguments: 1: String ("Bearer ") 2: String ("eyJhbGciOiJSUzI1NiIsImprdSI6Imh0dHBzOi8vcHQtZGVtby1jZi1ldTEwLXNieC5hdXRoZW50...)

But it expects one of these combinations: (Array, Any) (Date, Period) (DateTime, Period) (LocalDateTime, Period) (LocalTime, Period) (Number, Number) (Period, DateTime) (Period, LocalDateTime) (Period, Time) (Period, Date) (Period, LocalTime) (Time, Period)

4| "Authorization" : 'Bearer ' + payload.message, ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Trace: at anonymous::main (line: 4, column: 19)" evaluating expression: "output application/java

{ "Authorization" : 'Bearer ' + payload.message, "x-qos" : "1" }". `

I expect it will wokr just fines since if i hardcode the token. The flow will work just fine.

aled
  • 21,330
  • 3
  • 27
  • 34
TwinZaia
  • 7
  • 3
  • That doesn't look like Java. – tgdavies Jun 13 '23 at 06:17
  • You concatenate using `++` and not `+` in Dataweave. Refer this for basics of Dataweave https://developer.mulesoft.com/tutorials-and-howtos/dataweave/what-is-dataweave-getting-started-tutorial/ – Harshank Bansal Jun 13 '23 at 07:28
  • Please use text instead of images. See https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question for more details on the reason. Also use [code format](https://stackoverflow.com/editing-help#code) for code, errors and logs. – aled Jun 13 '23 at 11:18
  • @tgdavies it looks like DataWeave, the expression language in Mule 4. – aled Jun 13 '23 at 11:19

1 Answers1

1

Hope you are new to MuleSoft and DataWeave. As the error message indicates, you cannot use the "+" operator for string concatenation. To concatenate two or more strings, one option is to use the ++ function. Another more advanced technique is to use the $() syntax. You can read more about these methods here

Example:

Using ++ for concatenation

%dw 2.0
output application/json
---
{
    "Authorization": "Bearer " ++ payload.message
}

Using $() for concatenation

%dw 2.0
output application/json
---
{
    "Authorization": "Bearer $(payload.message)"
}
jarus
  • 201
  • 1
  • 2