Trouble using blob store API

I’m trying to use the blob store API from an edge function using NextJS, but any call I make to getStore fails with this error when I run my site using netlify dev:

⨯ MissingBlobsEnvironmentError: The environment has not been configured to use Netlify Blobs. To use it manually, supply the following properties when creating a store: siteID, token

It’s not clear where I’m supposed to get a token, and the fact that I need one at all seems kind of suspicious since the blobs page doesn’t say anything about needing a token or site ID.

My site name is spelling-bee-helper, but I haven’t uploaded any of my test code yet.

Have you trie using netlify link to link your CLI to a site?

I had a site linked and it didn’t work. I couldn’t find any option in the site settings to enable blobs.

Did you ever mange to fix this?

I’ve been trying to get blobs working with a site I’ve deployed to Netlify, but when using the following syntax:

const store = getStore('foo');

and got exactly the same issue: MissingBlobsEnvironmentError: The environment has not been configured to use Netlify Blobs. To use it manually, supply the following properties when creating a store: siteID, token

and now, when I’ve changed it to:

const store = getStore({ siteID: 'MY_SITE_ID', token: 'foo', name: 'foo' });

I get the following issue: Error: Netlify Blobs has generated an internal error: 401 response

I don’t understand what I’m doing wrong, as the docs suggest that the first code snippet should work?

@hrishikesh - any help would be much appreciated

The first snipper only works in Functions API v2 and Edge Functions and only when you’re linked the site to the CLI. If either of that is false, you might have to resort to: netlify/blobs: A TypeScript client for Netlify Blobs (github.com)

Thanks @hrishikesh. I have changed my functions to use the v2 syntax, but now I note that:

export default async (req: Request, ctx: Context) => {
   return new Response(JSON.stringify(req));
}

will return an {} (i.e. empty object), even if I make a GET request with headers.

Do you know why that may be?

Why are you trying to return the Request? Request is not a JSON that you can just stringify. It’s a constructor: Request: Request() constructor - Web APIs | MDN (mozilla.org)