Hello,
I have the following conundrum. In short, I want to retrieve an image in my Wix database associated with a specific ID using an URL call.
In more detail…
I have a database in Wix that has a bunch of images (right now it’s just text, but it’s only for testing) and each image is associated with a title. I would like to be able to make requests via a 3rd part software (Qualtrics) in order to be able to retrieve an image given a specific URL.
I’ve currently exposed my database to http requests, following Wix’s guide - https://support.wix.com/en/article/corvid-exposing-a-site-api-with-http-functions . Hence, my code looks like this in the “http-functions.js” file in the Backend, where “Qualtrics” is the name of my database, “_id” is the field key for the ID call:
import {ok, notFound, serverError} from 'wix-http-functions';
import wixData from 'wix-data';
export function get_myFunction(request) {
// URL looks like: https://www.mysite.com/_functions/myFunction/John/Doe
let options = {
"headers": {
"Content-Type": "application/json"
}
};
// query a collection to find matching items
return wixData.query("Qualtrics")
.eq("_id", request.path[0])
.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]}' was not found`
};
return notFound(options);
} )
// something went wrong
.catch( (error) => {
options.body = {
"error": error
};
return serverError(options);
} );
}
I would like to make a request so that I can only get the image from the URL. Currently, using the following URL - https://www.superrecognisers.com/_functions/myFunction/7b9737d8-6d97-452f-b2b5-57c3e274cc18 - throws an error that the requested path was not found (see “no matching items found” section in the code). When I use the developer URL - https://www.superrecognisers.com/_functions-dev/myFunction/7b9737d8-6d97-452f-b2b5-57c3e274cc18 - I see what I expect:
The way I make calls from the other service (Qualtrics) is very similar to entering the non-developer URL above. This is how it looks like:
(I think I can adapt the query parameters to my liking if I get the URL calls to work.)
Hence, my question is this: How can I make it so that when I enter a specific URL, e.g. https://www.superrecognisers.com/_functions/myFunction/7b9737d8-6d97-452f-b2b5-57c3e274cc18 I get the image associated with that id?
Any help or advice here would be greatly appreciated.
Thanks,
Nikolay