Hi there
I tested the API with the structure provide by the docs, but i am getting the following error:
422 Unprocessable Content
{
“detail”: [
{
“type”: “json_invalid”,
“loc”: [
“body”,
1
],
“msg”: “JSON decode error”,
“input”: {},
“ctx”: {
“error”: “Expecting value”
}
}
]
}
Could you help me to check please
Присоединяйтесь к обсуждению – добавьте комментарий ниже:
The issue with the JSON was that the payload object was not being properly converted to a JSON string before sending it in the request body. In the original code, the
body
field of theoptions
object was directly assigned the payload object:However, when sending data in a fetch request, the body needs to be a JSON string. So, the payload object needed to be converted into a JSON string using
JSON.stringify()
:By making this change, the payload was correctly formatted as a JSON string before being sent in the request body, resolving the issue.
Working fine !!! Thanks so much for your support, The API works really nice for I need.
for curiosity what it was the issue with the JSON?
async function numberToEnglish(number) {
const url = ‘https://numbers-to-words1.p.rapidapi.com/api/converter/’;
}
(async () => {
console.log(await numberToEnglish(45));
})();
Hello Saddem,
Thanks for the quick answer, I checked the points you send me and I am still getting the error, maybe it might be an error I can’t see.
Here is the code I am running:
async function numberToEnglish(number) {
const url = ‘https://numbers-to-words1.p.rapidapi.com/api/converter/’;
}
console.log(numberToEnglish(45));
Hi,
Thanks for reaching out. It looks like the API is having trouble decoding the JSON input you’re sending. The error message “Expecting value” typically indicates that there’s a syntax issue in the JSON structure.
Here are a few things to check:
Proper JSON Structure:
:
and are inside curly braces{}
.Data Types:
""
.If possible, can you share the JSON input you’re sending? It will help me pinpoint the issue more accurately.
I hope these suggestions help. If you have further details or questions, let me know, and I’d be happy to assist.