Trying to replicate the http-get function from the example documentation ( https://www.wix.com/corvid/reference/wix-http-functions.html ) to query a single column in any of my wix-site collections, but query result always returns {“error”:" … wasn’t found"}.
Could use any pointers to help troubleshoot this. Like, do my collections need to be associated with published website elements in published site pages?
Here’s what the latest iteration of my http-functions.js file looks like:
import { ok, notFound, serverError } from ‘wix-http-functions’;
import wixData from ‘wix-data’;
// URL looks like:
// https://www.mysite.com/_functions/myFunction/John/Doe
export function get_queryFunction(request)
{
let options =
{
“headers”:
{
“Content-Type”: “application/json”
}
};
// query a collection to find matching items
return wixData.query(“hosting-plans-fm”)
.eq(“ID”, request.path[0])
//.eq(“Disk”, request.path[1])
.find()
.then
(
(results) =>
{
// matching items were found
if (results.items.length > 0)
{
options.body =
{
“items”: results.items
};
return ok(options);
}
// no matching items found
options.body =
{
//“error”: ${request.path[0]} ${request.path[1]} wasn't found
“error”: ${request.path[0]} wasn't found
};
return notFound(options);
}
)
// something went wrong
. catch
(
(error) =>
{
options.body =
{
“error”: error
};
return serverError(options);
}
);
}
So I was fortunate (and persistent) enough to obtain an answer to this problem outside of the Wix Corvid Forum.
Thanks to the generosity of a skilled technical resource, I was pointed to a capitalization mistake with the keyField name in my wixData.query function.
As in line 18:
.eq("ID", request.path[0])
should instead read:
.eq("id", request.path[0])
So, for everyone else’s benefit, keep in mind that JavaScript is a case-sensitive scripting language, and this applies not just to keywords and event handlers, but also to object properties or methods.
My mistake was I was in referencing my data collection’s Field Names in the query rather than the Field Keys. In this case, “ID” is the Field Name and “id” is the Field Key.