Developers

Import Projects from CSV

Create IC Project projects from rows in a CSV file with Python.

This example reads project details from sample-projects.csv and creates each project through the IC Project API.

Prerequisites

  • Python 3
  • The requests package
  • An IC Project instance slug and authorization token
  • A CSV file whose columns are ordered as name, start date, end date, description, and status

Python script

Set authorization_token and instance_slug before running the script.

import-projects-from-csv.py
import csv
import requests

"""
You can find authorization token and instance slug in your instance settings panel.
"""
authorization_token = ""
instance_slug = ""

# open csv file
with open('sample-projects.csv') as csvfile:
    # csv reader
    reader = csv.reader(csvfile, delimiter=',')

    # skip first row (header)
    next(reader, None)

    # loop
    for project_name, date_start, date_end, description, status in reader:
        print(f"Creating project: {project_name}", end="")

        # https://developers.icproject.com/api-documentation/#tag/Project/operation/postProjectCollection
        params = {
            "name": project_name,
            "dateStartPlanned": date_start,
            "dateEndPlanned": date_end,
            "category": None,
            "tags": None,
            "description": description,
            "isBlameableRemovalEnabled": True,
            "status": status,
            "budget": 0
        }

        # necessary headers
        headers = {
            'X-Auth-Token': authorization_token,
            'Accept': 'application/json',
            'Content-type': 'application/json'
        }

        # make a request
        response = requests.post(
            f"https://app.icproject.com/api/instance/{instance_slug}/project/projects",
            json=params,
            headers=headers,
        )

        print("\t", response.status_code)

        # errors?
        if response.status_code != 200:
            print(response.content)

Run the script with:

python import-projects-from-csv.py

View the original source on GitHub

On this page