Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trouble syncing #1

Closed
hamoudydev opened this issue Aug 19, 2024 · 27 comments
Closed

trouble syncing #1

hamoudydev opened this issue Aug 19, 2024 · 27 comments

Comments

@hamoudydev
Copy link

this is my first time working with storyblok so maybe i'm an idiot but i followed the instructions but can't get anything to sync. just getting a 401 error from "errors/utils.js:64:19"

@preetamslot
Copy link
Contributor

preetamslot commented Aug 21, 2024

Hi, Sorry for the late reply.

Have you added your 3 tokens to the .env?
401 is a permission error.

STORYBLOK_PREVIEW_TOKEN=XXX
STORYBLOK_PERSONAL_TOKEN=XXX
STORYBLOK_SPACE_ID=000

https://astrorante.unfolding.io/news/getting-started/

if so, please share the complete error log.

@hamoudydev
Copy link
Author

Yes, I have those all, however I'm getting a problem for every file that has the
import { example } from "astro:env/server" with the problem being "Cannot find module 'astro:env/server' or its corresponding type declarations.

As for the terminal, here is what I'm getting
14:34:41 [200] /setup 26ms Error in searchListings: { message: 'Unauthorized', status: 401, response: 'Unauthorized' } 14:34:42 [400] /api/setup/datasources/pull 240ms Error in searchListings: { message: 'Unauthorized', status: 401, response: 'Unauthorized' } 14:34:52 [400] POST /api/setup/datasources/delete 326ms Error in searchListings: { message: 'Unauthorized', status: 401, response: 'Unauthorized' } 14:34:52 [400] /api/setup/datasources/pull 306ms Error in searchListings: { message: 'Unauthorized', status: 401, response: 'Unauthorized' } 14:34:55 [400] POST /api/setup/datasources/push 147ms

Oddly enough after a few refreshes it started working but couldn't sync everything, when I created a new space and updated the .env it no longer works again spitting out the same errors.

@preetamslot
Copy link
Contributor

The error on Pull is a Storyblok API error.

export const pullComponents = async () => {
  const components = await Storyblok.get(
    `/spaces/${STORYBLOK_SPACE_ID}/components/`,
    {},
  );

  return components?.data?.components;
};

This is uses an auth with your STORYBLOK_PERSONAL_TOKEN So it seems that your token does not have the right privileges :(

Can you try generating a new token?
https://app.storyblok.com/#/me/account?tab=token

@hamoudydev
Copy link
Author

hamoudydev commented Aug 23, 2024

Just tried and same error.

@preetamslot
Copy link
Contributor

I think it is related to:
withastro/astro#11816
withastro/astro#11380

So it looks like on your machine "astro:env/server" is not working,

  • What node version are you running?
  • can you run npx astro check and let me know if you get errors?

I have upgraded all packages, maybe it is already fixed in the latest astro.

If this does not work you could convert all astro:env instances

import { XXX } from "astro:env/server"
to
const XXX = import.meta.env.XXX

image

@hamoudydev
Copy link
Author

What node version are you running?

v20.15.1

can you run npx astro check and let me know if you get errors?

Zero errors

With the updated files I get a different kind of terminal error

14:26:29 [200] /setup 92ms Error in searchListings: { message: 'Not Found', status: 404, response: 'This record could not be found' } 14:26:30 [200] /api/setup/datasources/pull 300ms Error in searchListings: { message: 'Not Found', status: 404, response: 'This record could not be found' } 14:26:36 [200] /api/setup/datasources/pull 315ms

When I changed the astro:env instances I got all kinds of errors:
14:43:02 [ERROR] Unterminated string literal Stack trace: at C:/Users/Sone/Desktop/Astrorante-master/src/layouts/LayoutMinimal.astro:31:8 [...] See full stack trace in the browser, or rerun with --verbose. 14:43:02 [ERROR] Unterminated string literal Stack trace: at C:/Users/Sone/Desktop/Astrorante-master/src/layouts/LayoutMinimal.astro:31:8 [...] See full stack trace in the browser, or rerun with --verbose. 14:43:02 [astro-icon] Loaded icons from src/icons 14:43:37 [watch] src/layouts/LayoutMinimal.astro 14:43:38 [WARN] [vite] A PostCSS plugin did not pass the fromoption topostcss.parse. This may cause imported assets to be incorrectly transformed. If you've recently added a PostCSS plugin that raised this warning, please contact the package author to fix the issue. 14:43:38 [ERROR] Unterminated string literal Stack trace: at failureErrorWithLog (C:\Users\Sone\Desktop\Astrorante-master\node_modules\vite\node_modules\esbuild\lib\main.js:1472:15) [...] See full stack trace in the browser, or rerun with --verbose. 14:43:45 [watch] src/layouts/LayoutMinimal.astro 14:43:45 [ERROR] Unterminated string literal Stack trace: at failureErrorWithLog (C:\Users\Sone\Desktop\Astrorante-master\node_modules\vite\node_modules\esbuild\lib\main.js:1472:15) [...] See full stack trace in the browser, or rerun with --verbose. 14:47:15 [watch] src/pages/cms/index.astro 14:47:15 [ERROR] Unterminated string literal Stack trace: at failureErrorWithLog (C:\Users\Sone\Desktop\Astrorante-master\node_modules\vite\node_modules\esbuild\lib\main.js:1472:15) [...] See full stack trace in the browser, or rerun with --verbose. 14:47:26 [watch] src/util/translate.ts 14:47:26 [ERROR] Unterminated string literal Stack trace: at failureErrorWithLog (C:\Users\Sone\Desktop\Astrorante-master\node_modules\vite\node_modules\esbuild\lib\main.js:1472:15) [...] See full stack trace in the browser, or rerun with --verbose. 14:47:31 [watch] src/pages/api/contact/mailgun.ts 14:47:32 [ERROR] Unterminated string literal Stack trace: at failureErrorWithLog (C:\Users\Sone\Desktop\Astrorante-master\node_modules\vite\node_modules\esbuild\lib\main.js:1472:15) [...] See full stack trace in the browser, or rerun with --verbose. 14:47:34 [watch] src/pages/[...lang]/news/[...page].astro 14:47:35 [ERROR] Unterminated string literal Stack trace: at failureErrorWithLog (C:\Users\Sone\Desktop\Astrorante-master\node_modules\vite\node_modules\esbuild\lib\main.js:1472:15) [...] See full stack trace in the browser, or rerun with --verbose. 14:47:40 [watch] src/pages/[...lang]/[...slug].astro 14:47:40 [ERROR] Unterminated string literal Stack trace: at failureErrorWithLog (C:\Users\Sone\Desktop\Astrorante-master\node_modules\vite\node_modules\esbuild\lib\main.js:1472:15) [...] See full stack trace in the browser, or rerun with --verbose. 14:47:44 Configuration file updated. Restarting... 14:47:44 [WARN] [config] The adapter @astrojs/vercel/serverless provides experimental support for "astro:env getSecret". You may experience issues or breaking changes until this feature is fully supported by the adapter. 14:47:44 [types] Generated 3ms 14:47:45 [ERROR] Unterminated string literal Stack trace: at failureErrorWithLog (C:\Users\Sone\Desktop\Astrorante-master\node_modules\vite\node_modules\esbuild\lib\main.js:1472:15) [...] See full stack trace in the browser, or rerun with --verbose. 14:47:45 [astro-icon] Loaded icons from src/icons 14:47:48 [watch] src/layouts/LayoutMinimal.astro 14:47:48 [WARN] [vite] A PostCSS plugin did not pass the fromoption topostcss.parse. This may cause imported assets to be incorrectly transformed. If you've recently added a PostCSS plugin that raised this warning, please contact the package author to fix the issue. 14:47:49 [ERROR] Unterminated string literal Stack trace: at failureErrorWithLog (C:\Users\Sone\Desktop\Astrorante-master\node_modules\vite\node_modules\esbuild\lib\main.js:1472:15) [...] See full stack trace in the browser, or rerun with --verbose. 14:47:51 [watch] src/layouts/Layout.astro 14:47:52 [ERROR] Unterminated string literal Stack trace: at failureErrorWithLog (C:\Users\Sone\Desktop\Astrorante-master\node_modules\vite\node_modules\esbuild\lib\main.js:1472:15) [...] See full stack trace in the browser, or rerun with --verbose. 14:47:54 [watch] src/components/navigation/Link.astro 14:47:56 [ERROR] Unterminated string literal

@preetamslot
Copy link
Contributor

This is strange!

Can you share your .env (hello@unfolding.io) then I can see what happens on my computer.

@preetamslot
Copy link
Contributor

I don't know for sure, but your space ID has 7 chars, if I look at all my spaces have 6 chars.
Where do you get your space id?
The error is that storyblok cant find data on the space.

{
  message: 'Not Found',
  status: 404,
  response: 'This record could not be found'
}

@hamoudydev
Copy link
Author

Settings, space, space ID.

@preetamslot
Copy link
Contributor

I have created a space for you on my partner account and imported everything, not clear to me why it was not working for you.
When you accept the invite I will remove myself from the space.

Let me know if it works out for you!

@preetamslot
Copy link
Contributor

@hamoudydev
It looks like SB API has a lower rate limit on newer accounts, I have made some updates to the code.
If it fails hit the round refresh button and try the sync again.

Even with errors I saw some data being imported.

@hamoudydev
Copy link
Author

@hamoudydev It looks like SB API has a lower rate limit on newer accounts, I have made some updates to the code. If it fails hit the round refresh button and try the sync again.

Even with errors I saw some data being imported.

I noticed that, however when using my own API I'm still getting that 404 issue.

@NightmareVCO
Copy link

NightmareVCO commented Sep 21, 2024

Same here, I can't sync

02:01:11 [200] /api/setup/datasources/pull 303ms
ERROR::: {
  message: 'Not Found',
  status: 404,
  response: 'This record could not be found'
}

@preetamslot
Copy link
Contributor

@NightmareVCO This message is on pull, so this means that you don't have data sources.
What happens if you press the sync button? then it should hit the push endpoint.

Let me know.
Also a screen capture would help.

@NightmareVCO
Copy link

NightmareVCO commented Sep 21, 2024

@preetamslot

When I press the syncs button nothing happens

Screenshot 2024-09-21 at 11 36 42 AM Screenshot 2024-09-21 at 11 36 19 AM Screenshot 2024-09-21 at 11 36 04 AM

@hamoudydev
Copy link
Author

@NightmareVCO This message is on pull, so this means that you don't have data sources. What happens if you press the sync button? then it should hit the push endpoint.

Let me know. Also a screen capture would help.

do we have to manually enter the data into storyblok?

@preetamslot
Copy link
Contributor

preetamslot commented Sep 25, 2024

That would be a lot of work :(
I will do an other debug session.

The error looks like Storyblok Api cant find the data. Can you debug if the api gets your .env vars?

so in utils/storyblokApi.ts on line 230

export const pullDataSources = async () => {
  try {
    console.log("STORYBLOK_SPACE_ID:", STORYBLOK_SPACE_ID); // check space id
    console.log("STORYBLOK_PERSONAL_TOKEN:", token); // check token
    console.log("Storyblok SDK", Storyblok); // check SDK connection
    const dataSources = await Storyblok.get(
      `/spaces/${STORYBLOK_SPACE_ID}/datasources/`,
      {},
    );
    ...
    }

while testing I get this error when I enter a wrong STORYBLOK_SPACE_ID

ERROR::: {
  message: 'Not Found',
  status: 404,
  response: 'This record could not be found'
}

And this error when I enter a wrong STORYBLOK_PERSONAL_TOKEN

ERROR::: { message: 'Unauthorized', status: 401, response: 'Unauthorized' }

@preetamslot
Copy link
Contributor

To see that your current space id is, please add this code to src/pages/setup.astro on line 5

import { api } from "@util/storyblokApi";
const { data } = (await api.get("cdn/spaces/me", {})) as SpaceObj;
console.log("CURRENT SPACE DATA:", data);

@NightmareVCO
Copy link

@preetamslot In my case; when I run the code with

export const pullDataSources = async () => {
  try {
    console.log("STORYBLOK_SPACE_ID:", STORYBLOK_SPACE_ID); // check space id
    console.log("STORYBLOK_PERSONAL_TOKEN:", token); // check token
    console.log("Storyblok SDK", Storyblok); // check SDK connection
    const dataSources = await Storyblok.get(
      `/spaces/${STORYBLOK_SPACE_ID}/datasources/`,
      {},
    );
    ...
    }

the output is the same data that I have in my .env file and the client:

  client: ie {
    baseURL: 'https://api.storyblok.com/v1',
    timeout: 0,
    headers: HeadersList {
      cookies: null,
      [Symbol(headers map)]: [Map],
      [Symbol(headers map sorted)]: [Array]
    },

But then when I added this code:

import { api } from "@util/storyblokApi";
const { data } = (await api.get("cdn/spaces/me", {})) as SpaceObj;
console.log("CURRENT SPACE DATA:", data);

the output is:

[ERROR] {"message":"Unauthorized","status":401,"response":"Unauthorized"}
Possible dynamic routes being matched: src/pages/[...lang]/[...slug].astro.
Fetch Settings error: { message: 'Unauthorized', status: 401, response: 'Unauthorized' }
10:40:48 [ERROR] Can't fetch settings, is it published?

the error comes from:

export const getSettings = async (lang?: string | undefined) => {
  try {
    const { data: settingsData } = (await api.get(
      "cdn/stories/site-settings/settings",
      {
        version: import.meta.env.DEV ? "draft" : "published",
        language: !lang ? "default" : lang,
      },
    )) as ISbResult;

    return settingsData?.story?.content as SettingsStoryblok;
  } catch (error) {
    console.log("Fetch Settings error:", error);
    throw new Error("Can't fetch settings, is it published?");
^
  }
};

here you have a screenshot

CleanShot 2024-09-25 at 10 48 09@2x

@hamoudydev
Copy link
Author

@preetamslot In my case; when I run the code with

export const pullDataSources = async () => {
  try {
    console.log("STORYBLOK_SPACE_ID:", STORYBLOK_SPACE_ID); // check space id
    console.log("STORYBLOK_PERSONAL_TOKEN:", token); // check token
    console.log("Storyblok SDK", Storyblok); // check SDK connection
    const dataSources = await Storyblok.get(
      `/spaces/${STORYBLOK_SPACE_ID}/datasources/`,
      {},
    );
    ...
    }

the output is the same data that I have in my .env file and the client:

  client: ie {
    baseURL: 'https://api.storyblok.com/v1',
    timeout: 0,
    headers: HeadersList {
      cookies: null,
      [Symbol(headers map)]: [Map],
      [Symbol(headers map sorted)]: [Array]
    },

But then when I added this code:

import { api } from "@util/storyblokApi";
const { data } = (await api.get("cdn/spaces/me", {})) as SpaceObj;
console.log("CURRENT SPACE DATA:", data);

the output is:

[ERROR] {"message":"Unauthorized","status":401,"response":"Unauthorized"}
Possible dynamic routes being matched: src/pages/[...lang]/[...slug].astro.
Fetch Settings error: { message: 'Unauthorized', status: 401, response: 'Unauthorized' }
10:40:48 [ERROR] Can't fetch settings, is it published?

the error comes from:

export const getSettings = async (lang?: string | undefined) => {
  try {
    const { data: settingsData } = (await api.get(
      "cdn/stories/site-settings/settings",
      {
        version: import.meta.env.DEV ? "draft" : "published",
        language: !lang ? "default" : lang,
      },
    )) as ISbResult;

    return settingsData?.story?.content as SettingsStoryblok;
  } catch (error) {
    console.log("Fetch Settings error:", error);
    throw new Error("Can't fetch settings, is it published?");
^
  }
};

here you have a screenshot

CleanShot 2024-09-25 at 10 48 09@2x

just saved me a whole bunch of copy/paste lol but mine was the exact same thing.

@preetamslot
Copy link
Contributor

@NightmareVCO @hamoudydev

I see you get an Unauthorized error after adding:

import { api } from "@util/storyblokApi";
const { data } = (await api.get("cdn/spaces/me", {})) as SpaceObj;
console.log("CURRENT SPACE DATA:", data);

to the setup route.

This is good news! and means that your space preview token is not is loaded correct in the astro.config

 integrations: [
 storyblok({
      accessToken: env.STORYBLOK_PREVIEW_TOKEN,
      ....
      

can you console.log the env to see if it is loadEnv is working?

A quick fix would be to just hardcode your STORYBLOK_PREVIEW_TOKEN

Let me know if this helps

@NightmareVCO
Copy link

@preetamslot

So I added in astro.config.mjs line 14

console.log({env});

Result:

CleanShot 2024-09-26 at 11 50 03@2x

Even though I added the STORYBLOK_PREVIEW_TOKEN

CleanShot 2024-09-26 at 11 54 06@2x

There's no change at all. Same error:

11:57:20 [ERROR] {"message":"Unauthorized","status":401,"response":"Unauthorized"}

But now the error comes from:

CleanShot 2024-09-26 at 12 00 28@2x

@preetamslot
Copy link
Contributor

Then your STORYBLOK_PREVIEW_TOKEN is not working, can you generate a new one for your space?

@NightmareVCO
Copy link

@preetamslot So I did that:

CleanShot 2024-09-27 at 13 07 08@2x

and back to:

CleanShot 2024-09-27 at 13 04 38@2x

and:

Fetch Settings error: { message: 'Unauthorized', status: 401, response: 'Unauthorized' }
13:01:04 [ERROR] Can't fetch settings, is it published?

@NightmareVCO
Copy link

@preetamslot

Well I finally resolved the problem.

Probably @hamoudydev did the same as I did, I chose US server, that's why our spaces ID have 7 chars.
Well that doesn't work.

I created a new space at EU server, that generated me a 6 chars space ID and works perfect.

I guess it would be necessary to say that in docs or find a solution.

@hamoudydev
Copy link
Author

@preetamslot

Well I finally resolved the problem.

Probably @hamoudydev did the same as I did, I chose US server, that's why our spaces ID have 7 chars. Well that doesn't work.

I created a new space at EU server, that generated me a 6 chars space ID and works perfect.

I guess it would be necessary to say that in docs or find a solution.

can confirm that EU server 6 digit space ID works.

@preetamslot
Copy link
Contributor

That is indeed a setting in the astro.config.

export default defineConfig({
  integrations: [
    storyblok({
      accessToken: env.STORYBLOK_TOKEN,
      components: {
        // Add your components here
      },
      apiOptions: {
        // Choose your Storyblok space region
        region: 'us', // optional,  or 'eu' (default)
      },
    })
  ],
});

more info here:
https://docs.astro.build/en/guides/cms/storyblok/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants