Join the Webstudio community

Updated 3 months ago

Convert text to a number

At a glance

The community member is trying to send a JSON payload with a string value for the "tags" field, but the API expects an integer. They get an error saying the value cannot be deserialized as an integer. The community member tries to convert the string to an integer using parseInt(), but that doesn't work because the API doesn't support functions. After some discussion in the comments, another community member suggests the issue is with the template string, and the community member is able to resolve the issue.

Hey everyone, I've got this JSON in a resource using POST:

{
"currency": "USD",
"filtering": {
"destination": "55",
"tags": ["$system.search.experience"]
},
"pagination": {
"start": 1,
"count": 20
}
}

But get this error back from an API:

{
"ok": false,
"data": "Cannot deserialize value of type java.lang.Integer from String "$system.search.experience": not a valid java.lang.Integer value\n at [Source: REDACTED .........

So sounds like I need it to be an integer when it's a string. After multiple hours I cannot seem to get the right JSON to convert it into a number that the API will recognise

If I replace the system.search variable with a static number it works fine.

When I try {
currency: "USD",
filtering: {
destination: "55",
tags: [parseInt($system.search.experience)]
},
pagination: {
start: 1,
count: 20
}
}

It says "Functions are not support"

I wonder what I can do to get this into a number format?
O
R
5 comments
you seem to be sending "$system.search.experience" instead of the actual number, check your template string in the binding
In such cases you need to provide full information if you need to get a better answer
Thanks, when I put it in backticks I get this error
Attachment
image.png
Ah got it
Attachment
image.png
Working now! Thanks so much for the responce @Oleg Isonen your comment got me on the right track
Add a reply
Sign up and join the conversation on Discord