SiteClient Environment 404

I’m trying to use the Node SiteClient with a sandbox environment as described here : Using the NodeJS client - DatoCMS

const client = new SiteClient(DATO_CMS_API_KEY, { environment: “test” });

when I call client.items.create({…fields here…})

I get “404 NOT_FOUND (details: {})” as the response.

I have verified that the environment is ready as described here : List all environments - Environment - Content Management API

I see that the status is ‘ready’

what am I doing wrong? I’ve tried with different environments, all of which have a status of ‘ready’

hi @david.sellars

did you already check if the role linked to the access token is able to access sandbox environments?

yes. It does. I can also query https://graphql.datocms.com/environments/test and get items returned.

hi @david.sellars

when forking an environment, content’s IDs changes (because we duplicate the actual data in the database).

Is it possible that in your code ( client.items.create({…fields here…}) ) you are referencing a model with a ID that is valid for your primary environment, but not for your test environment?

If so, you should first search for the model by its api key ( https://www.datocms.com/docs/content-management-api/resources/item-type/self ). Api keys do not change when forking an environment. Then, once you have the model object, you can call client.items.create({…fields here…}) passing the right model ID to it.

Is this the case?

thanks @faber ! that’s really helpful! I had been using the modelId associated with the ‘primary’ and not the target environment!

Thanks for your quick reply!

great! :smiley: