Hi, trying to access api with API key but seems to be missing something
python script to access api
import requests
base_url = 'http://localhost:3000/api'
PAYLOAD_API_KEY = '0a7913e3-9d44-4f01-af0c-aeeff5a6bacf'
messages_url = base_url + '/messages'
# get messages
headers = {
"Authorization": f'users API-Key {PAYLOAD_API_KEY}',
}
response = requests.get(messages_url, headers=headers)
print(response.json())Users collection
import type { CollectionConfig } from 'payload/types'
export const Users: CollectionConfig = {
slug: 'users',
admin: {
useAsTitle: 'email',
},
auth: {
useAPIKey: true,
},
fields: [
// Email added by default
// Add more fields as needed
],
}Messages collection
import type { CollectionConfig } from 'payload/types'
export const Messages: CollectionConfig = {
slug: 'messages',
admin: {
useAsTitle: 'user',
},
auth: false,
fields: [
// Email added by default
// Add more fields as needed
{
name: 'user',
type: 'text',
},
{
name:'sender',
type: 'text',
},
{
name: 'content',
type: 'text',
}
],
}Anyone?
Hi Sagi. Your post has only been up for a few hours and you need to remember that the majority of the Payload developer base is US based. It is also the weekend, so you may get a slower response.
What is the error message you get when attempting to access the API with your key?
{'errors': [{'message': 'You are not allowed to perform this action.'}]}
This is an issue with your RBAC, which collection are you trying to query?
hi
@1007251491205152830Could you detail what the issue was and how you fixed it for future devs 😄
The issue was missing access configuration. I didn't really fully understand the issue nor the solution i've just shifted from the blank template to the website template and it worked
do u have an example?
Look at the user collection on web template
I think what
@1007251491205152830is trying to say is they did not have their access control settings configured correctly for the collection.
the website template that payload uses configures these access control settings for you. But it's still important to understand how the access control system functions in Payload
I just made everything true for now to see if it works, but I am unsure if i am missing something else?
I followed the example in the link here. Could you take a look to see if that makes sense?
Star
Discord
online
Get dedicated engineering support directly from the Payload team.