#Web CDN 401 error (Unauthorized)

1 messages · Page 1 of 1 (latest)

latent willow
#

Hello,

I'm currently exploring Appwrite and try to just connect it through web and get the content of a Database Collection.

I'm using CDN with this configuration in my HTML :

<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="JS/appWrite.js"></script>

appWrite.js :

const { Client, Databases, Query } = Appwrite;

const client = new Client();

const databases = new Databases(client);

client
.setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
.setProject("653ba2ff5cf5f9554ff6"); // Your project ID

const promise = databases.listDocuments(
"653ba48f8fb4b1a438f4",
"653ba54d486d9d936563"
);

promise.then(
function (response) {
console.log(response); // Success
},
function (error) {
console.log(error); // Failure
}
);

I don't understand how to fix the 401 error I encounter in the console (after looking into different documentations).
I have try to add in client setKey with an API Key without success.
Does anyone have a clue on how to fix this ?

Thank you in advance and have a good day !

latent willow
#

I also have platform set with * as hostname and i'm working local on the port 5500

misty cove
# latent willow I also have platform set with * as hostname and i'm working local on the port 55...

What’s your goal with the listDocuments? It seems like you’re listing documents by ID, Appwrite usually supports querying by ID via getDocument if you want to get one at a time, alternatively you could use a Query https://appwrite.io/docs/products/databases/queries

Harness the power of querying with Appwrite Databases. Discover various query options, filtering, sorting, and advanced querying techniques.

eager canopy
#

Did you have set permissions for such documents or collection?

misty cove
#

Ah yeah I missed that, that’ll do it too, there’s two types of SDK’s, the server SDK and the client side, the client side works by logging in and using the logged in users permissions to do things, the server side depends on the API key for permissions or a JWT/another form of authentication normally

narrow quartz
#

listDouments by document ids ?

#

Request failed with status code 400

#
let data = await appwrite_databases.listDocuments(appwrite_ids.databse.emo, 
        appwrite_ids.collection.config_menu, [
        Query.equal("$collectionId", finalIds)
    ]);
#

how to query?

eager canopy