Join the Webstudio community

Updated 2 months ago

Difference between online API and Webstudio

At a glance

The community member is using Payload to build an API and has noticed a difference between the data returned when testing the API online and the data received in Webstudio. Online, the API returns complete information, including details of images, users, etc., but in Webstudio, the community member receives a simplified version where certain objects are replaced by their IDs.

The community members discuss possible reasons for this difference, such as authentication issues, different queries, and depth parameters. They suggest using an API key instead of a JWT token, as it may be a simpler solution in this case.

Hello,

I've noticed a difference between the data returned by my API when I test it online and the data I receive in Webstudio. (I'm using Payload)

Online, the API returns all the complete information, including details of images, users, etc.

However, in Webstudio, I receive a simplified version where the featuredImage, user, theme and authors objects are replaced by their IDs.

Is this normal behavior? Is there a way to get the complete data in Webstudio, as I get it online?

Thanks in advance for your help!
1
B
M
O
35 comments
How do you test it?
This is my API :
And this is webstudio on teh same request url API :
{
"ok": true,
"data": {
"id": "674b3cbd06628cfaadc036cc",
"title": "TEST PATISSERIE",
"content": [
{
"children": [
{
"text": "Test 1"
}
],
"type": "h2"
},
{
"children": [
{
"text": "egfezoifilze neznifnzeifn ze"
}
]
},
{
"children": [
{
"children": [
{
"text": "rtehrthrththry"
}
],
"type": "li"
},
{
"type": "li",
"children": [
{
"text": "trehrtehrt"
}
]
},
{
"type": "li",
"children": [
{
"text": "rthrth"
}
]
}
],
"type": "ul"
}
],
"featuredImage": "674b3c8a06628cfaadc0367f",
"metaDescription": "meta description :)",
"keywords": [
{
"keyword": "patisserie",
"id": "674b3cbd5a0cad45c2e6b852"
}
],
"user": "6749ed09b65c60d02553af20",
"theme": "674b3cb706628cfaadc036ba",
"createdAt": "2024-11-30T16:26:37.573Z",
"updatedAt": "2024-11-30T16:50:55.267Z",
"authors": [
"674b416206628cfaadc0393d"
]
},
"status": 200,
"statusText": "OK"
}
What do y mean ? @TrySound
he means how did you get the data whe you compared to what webstudio gets
what's the difference? between the attachmenet and the posted data? seems the same to me
the data in the attachment seems to start at {data: {here}}
look for example in "featured Image". there are not all the children in Webstudio.
then you are not fetching the same your query must be different then between your tests
And the data I get from the attachment, I checked it in 2 ways: - On payload, in order to create the API url we can see the data we will get - By typing the API URL on Google on my server
the difference is in your queries, 100%
I have I checked and it is indeed the same url
otherwise data would be the same πŸ˜‰
and you are not showing us your queries
so no way to verify
πŸ˜…πŸ€£ Ok I will check again
And I will send y the queries πŸ™‚
Try to check the parameters depth on Payload, or try to query it on incognito to see if there is an access in your schema that relies on loggedin user
Yes you are correct, the reason comes from the fact that I am not authenticated. I'm currently looking into how to do this in Payload in fetch
Ok I need your help.
I almost managed to configure everything. This really comes from an authentication problem.
So I have the idea to use "JWT Tokens".
First I retrieve the token, and then I want to use it in my fetch request to display my blog article.
It works, but a token may change
Attachment
image.png
But the problem is there, I would have liked to use the "editor expression", but in the available variables I do not have "PAYLOAD_AUTHEN". Maybe this authentication method is a bad idea?
Anyone have an idea?
Attachment
image.png
is payload not providing a static token somewhere?
I didn't find it...
I'm lost here 😭
start using gpt for questions like this
Attachment
image.png
this is what I done with the first capture
but is a JWT Token.
Paylaod not provide a static token
Is there no way to use this token like in my capture 3?
you did the second approach
first is you provide a token in your .env
payload lets you define the token
Ok sorry, I didn't understand. Ok I will test that
And I've also been using Gemini since the beginning to help me πŸ™‚
The easiest solution is to use api key instead of jwt

You can find on payloadcms docs to do so, by set a boolean on useApiKey on collection that have auth true

Then you can just use this user api key to access your data
yeah api key is better in your case, no need for a separate request to exchange token
Add a reply
Sign up and join the conversation on Discord