Copying env vars from one site to another

I am trying to copy my environment variables from one Netlify site to another from my command line locally.
I have Netlify cli installed and I am logged in. I have also generated a personal access token.
I tried with
npx netlify-copy-env-vars from-site-domain-whole-url to-site-domain-whole-url --token=23453153asdfasfdadcacafrfdafdasffdsa
and
npx netlify-copy-env-vars name-of-site-from name-of-site-to --token=23453153asdfasfdadcacafrfdafdasffdsa

these tokens here are in the example from GitHub - morrislaptop/netlify-copy-env-vars: Copy env vars from one site to another
not my personal token. However this does not work. Gives me error:
JSONHTTPError: Not Found

is there another way? or how to get this way to work? Thanks folks!

I’d take about 10 steps back and get the plain calls made using something like curl first, before moving them into packages whose source code our staff won’t be able to help you debug.

Per this article:

…what are the calls to show/set? Let’s get those working from or postman or something - we’ll be able to help that far - and then you can embed them in node scripts afterwards but our staff won’t be able to help debug that code :slight_smile:

Thanks @fool It looks like I better build that function my self. I already started and have now a node repo where I get the env variables, now I need to build them too :slight_smile:

Plan (for now) is to read the local .env file and push that to Netlify admin. With this method I can have in sync the local repo and Netlify. It is way easier and quicker to write quickly a text file than clicking anything in the admin.

1 Like

I’m a bit late to the party but if anyone is looking for this in future a bit of grep and sed sorted it out for me.

NETLIFY_SITE_ID=<existing_site> netlify env:list | grep -E '\| [A-Z_]+ +\|' | sed -E 's/\| ([^ ]+) +\| ([^ ]+).*/\1=\2/' > env

This gives you an env file that includes all the vars from the old site.

NETLIFY_SITE_ID=<new_site> netlify env:import env

This imports those env vars to the new site. If you need to change anything you can edit the file before you import it.

2 Likes