[SOLVED] searchNFTs returns 400 errorCode

I have been using “react-moralis”: “^1.4.0” for a while now. Few weeks ago I am getting 400 without error message when calling Moralis.Web3API.token.searchNFTs. Please advise but keep in mind that updating to version 2 is not an option right now.
If I search for “bored” it fails. If I search for “bored apes” it succeeds.

This a snippet of what I am using:

try {
const options = {
q: searchQuery,
chain: chain,
filter: “name”,
limit: 100,
};
const response = await Moralis.Web3API.token.searchNFTs(options);

} catch (error) {
console.log("error ", error);
}

Hi @Cwhits

This could be due to large data returned from the response. Can you try adding disable_total parmas with a value as true in your code?

Adding it will return the data without total value and it will return the data much faster.

try {
const options = {
q: searchQuery,
chain: chain,
filter: “name”,
limit: 100,
disable_total: true // 👈
};
const response = await Moralis.Web3API.token.searchNFTs(options);

} catch (error) {
console.log("error ", error);
}

Can you try using the above code to check if it solves the error?

Just did but received the same error. You can check the site: https://www.collats.com/search and search by name.

I just tested it from the website. It seems that disable_total is not yet added to the payload. Make sure the latest code is deployed successfully.

Haven’t published a new version until I can fix it in development. But after adding the “disable_total” still the problem persists.

Is it the same error? Or do you see a different error message?

Exactly the same error.

Ok, I am having a look at your server and will update you here if I find something.

Hi @Cwhits

It seems like this is an issue from the API itself. I have reported it to the devs. Will let you know when I have more details from the devs :raised_hands:

2 Likes

Hi @Cwhits

The issue is fixed now. Your code with disable_total as true should work as expected.


You can also add other parameters like format or from/to_date to narrow down the results for faster response from API. This should help when the response has a huge number of results.

try {
const options = {
q: searchQuery,
chain: chain,
filter: “name”,
limit: 100,
disable_total: true, // 👈
format: "decimal", // 👈
};
const response = await Moralis.Web3API.token.searchNFTs(options);

} catch (error) {
console.log("error ", error);
}

POST https://xxxxxxxxxxxxx.usemoralis.com:2053/server/functions/searchNFTs 400
(anonymous) @ trycatch.js:161
(anonymous) @ instrument.js:250
(anonymous) @ xhr.js:210
e.exports @ xhr.js:15
e.exports @ dispatchRequest.js:56
u.request @ Axios.js:108
n.forEach.u. @ Axios.js:140
(anonymous) @ bind.js:9
(anonymous) @ MoralisWeb3Api.js:341
u @ runtime.js:63
(anonymous) @ runtime.js:294
(anonymous) @ runtime.js:119
i @ asyncToGenerator.js:5
s @ asyncToGenerator.js:27
(anonymous) @ asyncToGenerator.js:34
t @ export.js:18
(anonymous) @ asyncToGenerator.js:23
(anonymous) @ MoralisWeb3Api.js:380
(anonymous) @ MoralisWeb3Api.js:229
u @ runtime.js:63
(anonymous) @ runtime.js:294
(anonymous) @ runtime.js:119
i @ asyncToGenerator.js:5
s @ asyncToGenerator.js:27
(anonymous) @ asyncToGenerator.js:34
t @ export.js:18
(anonymous) @ asyncToGenerator.js:23
(anonymous) @ MoralisWeb3Api.js:243
(anonymous) @ MoralisWeb3Api.js:1080
u @ runtime.js:63
(anonymous) @ runtime.js:294
(anonymous) @ runtime.js:119
i @ asyncToGenerator.js:5
s @ asyncToGenerator.js:27
(anonymous) @ asyncToGenerator.js:34
t @ export.js:18
(anonymous) @ asyncToGenerator.js:23
(anonymous) @ MoralisWeb3Api.js:1099
(anonymous) @ searchByName.js:20
s @ runtime.js:45
(anonymous) @ runtime.js:274
forEach.e. @ runtime.js:97
n @ _async_to_generator.mjs:3
s @ _async_to_generator.mjs:25
(anonymous) @ _async_to_generator.mjs:32
(anonymous) @ _async_to_generator.mjs:21
(anonymous) @ search-dcc29c8a1e7899a8.js:1
(anonymous) @ search.js:57
s @ runtime.js:45
(anonymous) @ runtime.js:274
forEach.e. @ runtime.js:97
n @ _async_to_generator.mjs:3
s @ _async_to_generator.mjs:25
(anonymous) @ _async_to_generator.mjs:32
(anonymous) @ _async_to_generator.mjs:21
(anonymous) @ search-dcc29c8a1e7899a8.js:1
L @ SearchBar.js:61
Oe @ react-dom.production.min.js:54
Ae @ react-dom.production.min.js:54
(anonymous) @ react-dom.production.min.js:55
Ir @ react-dom.production.min.js:105
Ur @ react-dom.production.min.js:106
(anonymous) @ react-dom.production.min.js:117
ss @ react-dom.production.min.js:274
Le @ react-dom.production.min.js:52
Hr @ react-dom.production.min.js:109
Kn @ react-dom.production.min.js:74
Qn @ react-dom.production.min.js:73
i @ helpers.js:85
Show 3 more frames
searchByName.js:43 error Error: {}
at Function. (MoralisWeb3Api.js:366:23)
at u (runtime.js:63:40)
at Generator._invoke (runtime.js:294:22)
at Generator.throw (runtime.js:119:21)
at i (asyncToGenerator.js:5:20)
at l (asyncToGenerator.js:31:9)

Hi @Cwhits

Did you update your code to use the disable_total parameter?

Can you check the request payload in the network tab for verification

1 Like

It’s working!!! Thanks @johnversus!!!

1 Like

Hi, Cwhits.

Thank you for the compliment! :grinning_face_with_smiling_eyes:

Could you please leave a review on our Trustpilot about the Moralis services and the support you have received from us? It will mean a lot for us to spread the positive word; as you can see, we don’t have many reviews as of yet.

You can find out Trustpilot here - https://www.trustpilot.com/review/moralis.io

Let me know if there’s anything I can do for you. Thanks a lot!

2 Likes