Deepbits Platform: Delete a project

This API endpoint (DELETE /project/{project_id}) allows users to delete a project on the Deepbits platform by specifying the project ID (project_id) in the URL path.

Delete Project by ID. The delete_project function deletes a project from the Deepbits platform by specifying the project's ID.

Delete Project by Name. The delete_projects_by_name function deletes a project from the Deepbits platform by specifying the project's name.

Users must authenticate using an API key (x-api-key header) in the request headers. Upon successful deletion, the API returns a JSON response (200 OK) confirming the deletion.

Below is a demo script demonstrating how to delete a project by its ID (PROJECT_ID) and delete multiple projects by name (PROJECT_NAME). Adjust the placeholders , , and with your specific values for integration.

import requests

API_KEY = '<Your API key generated from app.deepbits.com>'
API_BASE = 'https://api.deepbits.com/api/v1'

PROJECT_ID = '<Your project id>'
PROJECT_NAME = '<Your project name>'

def main():
    # delete a project by id
    response = delete_project(PROJECT_ID)
    print(response)

    # delete projects by name
    delete_projects_by_name(PROJECT_NAME)

def delete_project(project_id):
    try:
        url = f"{API_BASE}/project/{project_id}"
        headers = {
            "accept": "application/json",
            "x-api-key": API_KEY
        }
        
        response = requests.delete(url, headers=headers)
        response.raise_for_status()  # Raise an exception for HTTP errors
        
        return response.json()  # Return the JSON response
    except requests.RequestException as e:
        print(f"An error occurred: {e}")
        return None

def delete_projects_by_name(project_name):
    project_id_list = get_project_id_list_by_name(project_name)
    print('project_id_list:', project_id_list)
    for project_id in project_id_list:
        response = delete_project(project_id)
        print(response)

def get_project_id_list_by_name(project_name):
    url = f"{API_BASE}/projects"
    headers = {
        "accept": "application/json",
        "x-api-key": API_KEY
    }
    project_id_list = []
    response = requests.get(url, headers=headers)
    if 'data' in response.json():
        for x in response.json().get('data', {}):
            if x.get('name', None) == project_name:
                project_id_list.append(x.get('_id', {}))
    return project_id_list

if __name__ == "__main__":
    main()