Skip to content

Instantly share code, notes, and snippets.

@zakaria-chahboun
Last active September 13, 2021 13:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zakaria-chahboun/f77d4319fb32e2331cb51b404e2fc4ed to your computer and use it in GitHub Desktop.
Save zakaria-chahboun/f77d4319fb32e2331cb51b404e2fc4ed to your computer and use it in GitHub Desktop.
How to remove all GitLab projects by API

First of all you need to create a personal access token:

Go to profile/preferences/access tokens or just click here

alt text

Repalce your token in token variable in this code bellow:

const axios = require("axios");

// Your authorization token here
const token = "YOUR_ACCESS_TOKEN";

// fetch all projects
axios
  .get("https://gitlab.com/api/v4/projects?visibility=private", {
    headers: {
      Authorization: `Bearer ${token}`,
    },
  })
  .then(async function (response) {
    // get all projects IDs
    let ids = response.data.map((e) => e.id);
    // delete all
    for (let el of ids) {
      await axios.delete(`https://gitlab.com/api/v4/projects/${el}/`, {
        headers: {
          Authorization: `Bearer ${token}`,
        },
      });
    }
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  });

You can change the visibility ?visibility=private or ?visibility=public

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment