Is there a way to duplicate a site using API ?
In my usecase, I configure a site with my private gitlab repository and then need to duplicate the site with just a different environment variable and domain.
I would like them to deploy automatically when I commit/push to that repository.
At a high level, no. There is no “create an exact copy of any site” API call. And in fact some settings are probably not “Create”-able, but must be activated with one call and then configured with another. You will spend substantial time trying to reverse engineer exactly how to configure domain aliases and other site settings such as large media, permissions, notifications, etc. Creating a generic site is easy (Netlify API documentation); creating a site with many specific settings is hard, nonintuitive (some settings can be passed to the siteUpdate call, others have to be passed to the updateSite or createSiteSnippet calls), and our docs do not attempt to address that use case.
But, as far as how your site builds and some settings on it - things like asset optimization, environment variables, redirects, etc - you can use config as code: netlify.toml! This file lets you control how and what to build, what variables to set, what asset optimizations, redirects, and headers a site needs. All in one file, that is intended to be used this way. Here’s the docs on it:
As far as “how you populate the toml with your values on gitlab and trigger the creation”, not sure about that. You might consider using the Deploy to Netlify button - which leverages the netlify.toml to set custom variables a public repo: Create deploys | Netlify Docs