### Example CSV Structure Source: https://developers.icproject.com/integrating-ic-project-with-csv-automated-user-import-example Example CSV file structure for user data. ```csv email,firstName,lastName,canLogIn,phoneNumber,jobPosition,department,roleSets,hourlyRate john.doe@example.com,John,Doe,true,123-456-7890,3fa85f64-5717-4562-b3fc-2c963f66afa6,3fa85f64-5717-4562-b3fc-2c963f66afa6,3fa85f64-5717-4562-b3fc-2c963f66afa6,30 jane.smith@example.com,Jane,Smith,true,987-654-3210,3fa85f64-5717-4562-b3fc-2c963f66afa6,3fa85f64-5717-4562-b3fc-2c963f66afa6,3fa85f64-5717-4562-b3fc-2c963f66afa6,25 alice.johnson@example.com,Alice,Johnson,false,555-123-4567,3fa85f64-5717-4562-b3fc-2c963f66afa6,3fa85f64-5717-4562-b3fc-2c963f66afa6,3fa85f64-5717-4562-b3fc-2c963f66afa6,20 bob.brown@example.com,Bob,Brown,true,555-765-4321,,3fa85f64-5717-4562-b3fc-2c963f66afa6,,40 ``` -------------------------------- ### API Authorization Example Source: https://developers.icproject.com/faq Example of how to make an API request including the X-Auth-Token header. ```http GET /api/instance/INSTANCE_SLUG/project/projects HTTP/1.1 Host: app.icproject.com User-Agent: My Custom Script Accept: application/json X-Auth-Token: YOUR_AUTHORIZATION_TOKEN ``` -------------------------------- ### Example CSV Format Source: https://developers.icproject.com/how-to-import-contractors-to-ic-project-from-csv-using-python An example structure for the CSV file containing contractor data. ```csv name,email,phone John Doe,john.doe@example.com Jane Smith,jane.smith@example.com,+48223456789 ``` -------------------------------- ### Install Requests Library Source: https://developers.icproject.com/export-orders-from-apilo-to-ic-project-and-create-tasks-using-python Command to install the Python requests library using pip. ```bash pip install requests ``` -------------------------------- ### Example CSV File Format Source: https://developers.icproject.com/importing-costs-from-csv-to-ic-project-using-python This is an example of the CSV file format that the script expects, including columns for name, description, pricing, dates, billing status, cost category, tax rate, and project. ```csv name,description,priceNet,priceGross,date,isBilled,isPosted,category,taxRate,taxRateValue,project Sample Cost 1,Description for cost 1,100.00,123.00,2024-09-15,true,false,Category A,Standard Tax,10,Project X Sample Cost 2,Description for cost 2,200.00,246.00,2024-09-16,false,true,Category B,Reduced Tax,5, ``` -------------------------------- ### Setting Up Configurations Source: https://developers.icproject.com/integrating-ic-project-with-csv-automated-user-import-example Defines constants for the CSV file path, IC Project slug, API endpoint, and API key. ```python CSV_FILE_PATH = './users.csv' ICP_SLUG = 'your_ic_project_slug' # Replace with actual slug API_ENDPOINT = f'https://app.icproject.com/api/instance/{ICP_SLUG}/user/users' API_KEY = 'your_api_key' # Replace with actual API key ``` -------------------------------- ### Importing Libraries Source: https://developers.icproject.com/integrating-ic-project-with-csv-automated-user-import-example Imports necessary Python libraries for CSV processing and API requests. ```python import pandas as pd import requests import json ``` -------------------------------- ### User Created Source: https://developers.icproject.com/webhooks Example JSON payload for a user creation webhook. ```json { "userId": "61b78364-618e-4001-90ae-9de48328a93a", "shortCode": "qwerty", "firstName": "John", "lastName": "Doe", "email": "KU6ZD@example.com", "pictureSm": "https://example.com/pictureSm.jpg", "pictureLg": "https://example.com/pictureLg.jpg", "isExternal": false, "canLogIn": true, "hourlyRate": 0.0, "hoursPerWorkDay": 8, "tasksPerWorkDay": 5, "jobPositionId": "fcfc6cef-e519-4a60-8e75-d9b69080cffe", "jobPositionName": "Job Position Name", "contractorId": "1d6b977d-d095-41dc-a5c4-e2516eaf33eb", "contractorName": "Contractor Name", "phoneNumber": "+1234567890", "language": "en", "is24HourFormat": false, "timezone": "UTC", "decorator": "#ffffff" } ``` -------------------------------- ### Invoice Created Source: https://developers.icproject.com/webhooks Example payload for an invoice created event. ```json { "invoiceId": "790cf71a-d7e3-48a9-b93d-84f3dd6b23b6", "number": "123/abc", "dateSale": "2023-01-01", "dateIssue": "2023-01-01", "kind": "FV", "currencyCode": "EUR", "priceNet": 100.0, "priceGross": 120.0, "priceTax": 20.0 } ``` -------------------------------- ### Reading CSV and Sending API Requests Source: https://developers.icproject.com/integrating-ic-project-with-csv-automated-user-import-example Reads the CSV file, iterates through each row, transforms the data, and sends a POST request to the IC Project API to add users. ```python df = pd.read_csv(CSV_FILE_PATH) for index, row in df.iterrows(): user_data = transform_row(row) print(f"Preparing data for user: {user_data['email']}") headers = { 'X-Auth-Token': API_KEY, 'Content-Type': 'application/json', 'Accept': 'application/json', } response = requests.post(API_ENDPOINT, headers=headers, data=json.dumps(user_data)) if response.status_code == 201: print(f"User {user_data['email']} has been successfully added.") else: print(f"Error adding user {user_data['email']}: {response.status_code} - {response.text}") print("Import process completed.") ``` -------------------------------- ### Contractor Created Source: https://developers.icproject.com/webhooks Example JSON payload for a contractor creation webhook. ```json { "contractorId": "41e26aa9-3648-414f-9e9b-a7bb4a20d73c", "name": "Contractor Name", "email": "KU6ZD@example.com", "accountingEmail": "KU6ZD@example.com", "shortCode": "qwerty", "pictureSm": "https://example.com/pictureSm.jpg", "pictureLg": "https://example.com/pictureLg.jpg" } ``` -------------------------------- ### Example Usage Source: https://developers.icproject.com/importing-costs-from-csv-to-ic-project-using-python This code snippet demonstrates how to set up the necessary variables, including the CSV file path, API endpoint, and authentication headers, and then calls the `csv_to_costs` and `send_costs_to_api` functions to import cost data. ```python csv_file = 'sample-costs.csv' # Path to the CSV file instance_slug = 'your-instance-slug' # Your instance slug api_url = f'https://app.icproject.com/api/instance/{instance_slug}' # API endpoint api_key = 'your-api-key' # Your API key headers = { 'X-Auth-Token': api_key, # Authorization token 'Content-Type': 'application/json', # Content type for the request 'Accept': 'application/json', # Expected response type } costs_data = csv_to_costs(csv_file, api_url, headers) send_costs_to_api(costs_data, api_url, headers) ``` -------------------------------- ### Creating Projects from CSV Data Source: https://developers.icproject.com/creating-projects-with-csv-data Iterates through each row of the CSV file, unpacking the data into variables for project name, start date, end date, description, and status. ```python for project_name, date_start, date_end, description, status in reader: ``` -------------------------------- ### Transforming CSV Row to JSON Source: https://developers.icproject.com/integrating-ic-project-with-csv-automated-user-import-example A function to convert a CSV row into the JSON format required by the IC Project API. ```python def transform_row(row): return { "email": row['email'], "firstName": row['firstName'], "lastName": row['lastName'], "canLogIn": row.get('canLogIn', 'true').lower() == 'true', "phoneNumber": row.get('phoneNumber', ''), "jobPosition": row.get('jobPosition', 'default-job-position-id'), "department": row.get('department', 'default-department-id'), "roleSets": [row.get('roleSets', 'default-role-set-id')], "hourlyRate": float(row.get('hourlyRate', 0)) } ``` -------------------------------- ### Apilo Orders URL with Filter Source: https://developers.icproject.com/export-orders-from-apilo-to-ic-project-and-create-tasks-using-python Example of constructing an Apilo orders URL with a filter. ```python url = f"https://{APILO_INSTANCE_SLUG}.apilo.com/rest/api/orders&createdAfter=2022-03-01T14%3A40%3A33%2B0200 ``` -------------------------------- ### Task Completed Source: https://developers.icproject.com/webhooks Example JSON payload for a task completion webhook. ```json { "taskId": "e13443f9-9ca6-4bf4-96e1-244bf7c06714", "name": "Task Name", "number": 1, "shortCode": "qwerty", "boardId": "75e73a07-0384-43e8-b09c-a6926cf585a5", "stageId": "09cec81d-669f-42de-941a-02b43306e104", "projectId": "2f970373-6929-4d5d-bf83-c2ff8b7aeaf5", "weight": 1, "status": "in-preparation" } ``` -------------------------------- ### User Deleted Source: https://developers.icproject.com/webhooks Example payload for a user deleted event. ```json { "userId": "31641e7e-1c0f-47e3-8a42-d46a561d9a62" } ``` -------------------------------- ### Task Comment Created Source: https://developers.icproject.com/webhooks Example JSON payload for a task comment creation webhook. ```json { "taskCommentId": "22698227-96df-4e56-9f6b-bcefaab3c7be", "taskId": "6e0f4448-cb90-41e3-8c97-18920c0d37f9", "projectId": "0ec6a0e7-13c8-454a-be08-da9471e356b2", "userId": "be1748c9-b4e5-4577-9cbe-ae2abef88cb1", "content": "Comment content", "createdBy": "18a41b6f-35dd-458f-ae20-0b1a7883d17c" } ``` -------------------------------- ### Invoice Deleted Source: https://developers.icproject.com/webhooks Example payload for an invoice deleted event. ```json { "invoiceId": "561db292-e320-47a1-aa20-2203758e0c3f" } ``` -------------------------------- ### Making an API Request to Retrieve Project Data Source: https://developers.icproject.com/exporting-projects-to-csv The script makes a GET request to the IC Project API to fetch the list of projects. The necessary headers, including the authorization token, are included in the request. ```python headers = { 'X-Auth-Token': authorization_token, 'Accept': 'application/json', } response = requests.get( f"https://app.icproject.com/api/instance/{instance_slug}/project/projects?pagination=0", headers=headers, ) ``` -------------------------------- ### Task User Assigned Source: https://developers.icproject.com/webhooks Example JSON payload for a task user assignment webhook. ```json { "projectId": "4df94cee-2d7a-4656-873d-7d424e526a4b", "taskId": "a98500bb-ef6a-440b-936e-154bca55b9af", "userId": "54f071c3-f53f-4e93-a6b3-418def66fc82" } ``` -------------------------------- ### Contractor Deleted Source: https://developers.icproject.com/webhooks Example JSON payload for a contractor deletion webhook. ```json { "contractorId": "d5b7c600-cf47-4d12-b7f3-227e7e9fe02d" } ``` -------------------------------- ### Reported Time Created Source: https://developers.icproject.com/webhooks Example JSON payload for a reported time creation webhook. ```json { "reportedTimeId": "ce676377-021a-4d4d-9961-a8a6d9890f55", "reportedDate": "2022-01-01", "seconds": 3600, "taskId": "adaa882e-dc23-4b79-a84f-f8a8061ea480", "projectId": "9a031b32-f522-425c-b9a7-4775f0134588", "userId": "8634a2a5-c649-4e9e-84e1-86527626fd62", "timeTypeId": "fa123ba0-8933-4e2e-899f-e8c254f54091", "description": "Description" } ``` -------------------------------- ### Task User Unassigned Source: https://developers.icproject.com/webhooks Example JSON payload for a task user unassignment webhook. ```json { "projectId": "2834427c-6ecd-408f-a97a-20132db0ec73", "taskId": "7fcb5bea-8d87-433e-89eb-5fc0ffc8c513", "userId": "fbdd9613-fa3d-470f-8fac-843c6ac7d649" } ``` -------------------------------- ### Reported Time Deleted Source: https://developers.icproject.com/webhooks Example JSON payload for a reported time deletion webhook. ```json { "reportedTimeId": "8dca5aa9-12cb-4914-a494-9d678ed11558", "projectId": "48283a55-a597-4928-826b-51be802f0722" } ``` -------------------------------- ### Get Board Column ID Source: https://developers.icproject.com/export-orders-from-apilo-to-ic-project-and-create-tasks-using-python Function to retrieve the ID of the first column for a given IC Project board. ```python def get_board_column_id(board_slug): url = f"https://app.icproject.com/api/instance/{IC_PROJECT_INSTANCE_SLUG}/project/boards/s/{board_slug}/get-kanban-board" headers = { 'X-Auth-Token': IC_PROJECT_API_KEY, 'Content-Type': 'application/json', 'Accept': 'application/json', } try: response = requests.get(url, headers=headers) response.raise_for_status() # Raise an exception for HTTP errors board_id = response.json().get('id') if not board_id: raise ValueError("Board ID not found in the response") except requests.RequestException as e: print(f"Error retrieving board ID: {e}") return None except ValueError as e: print(e) return None url = f"https://app.icproject.com/api/instance/{IC_PROJECT_INSTANCE_SLUG}/project/boards/{board_id}/board-columns" try: response = requests.get(url, headers=headers) response.raise_for_status() # Raise an exception for HTTP errors return response.json()[0].get('id') # Assuming you want the first column's ID except requests.RequestException as e: print(f"Error retrieving board columns: {e}") return None ``` -------------------------------- ### Task Comment Deleted Source: https://developers.icproject.com/webhooks Example JSON payload for a task comment deletion webhook. ```json { "taskCommentId": "cdaa97ea-a737-4d34-a32d-b7d5f6636ca3", "projectId": "d8fe6a25-3700-4291-b3b8-eb6eb9cca94b" } ``` -------------------------------- ### Set Up Headers Source: https://developers.icproject.com/how-to-import-contractors-to-ic-project-from-csv-using-python Configures the headers for the API request, including the authorization token, content type, and expected response format. ```python headers = { 'X-Auth-Token': API_KEY, 'Content-Type': 'application/json', 'Accept': 'application/json', } ``` -------------------------------- ### Define API and File Details Source: https://developers.icproject.com/how-to-import-contractors-to-ic-project-from-csv-using-python Specifies the path to the CSV file, the IC Project slug, the API endpoint, and the API key for authentication. ```python CSV_FILE_PATH = 'contractors.csv' # Path to your CSV file ICP_SLUG = 'your-icp-slug' # Your IC Project slug API_ENDPOINT = f'https://app.icproject.com/api/instance/{ICP_SLUG}/crm/contractors' API_KEY = 'your-api-key' # Your API key ``` -------------------------------- ### Authentication and Instance Information Source: https://developers.icproject.com/exporting-projects-to-csv Next, the script declares two variables: `authorization_token` and `instance_slug`. These variables store the authorization token and instance slug needed for API authentication. Make sure to replace the empty strings with the actual values obtained from your IC Project instance settings. ```python authorization_token = "YOUR_AUTHORIZATION_TOKEN" instance_slug = "YOUR_INSTANCE_SLUG" ``` -------------------------------- ### Reading and Processing the CSV File Source: https://developers.icproject.com/creating-projects-with-csv-data Opens the 'sample-projects.csv' file and creates a csv.reader object to parse its content, using a comma as the delimiter. ```python with open('sample-projects.csv') as csvfile: reader = csv.reader(csvfile, delimiter=',') ``` -------------------------------- ### Run the Script Source: https://developers.icproject.com/how-to-import-contractors-to-ic-project-from-csv-using-python This code block ensures that the `main` function is called when the script is executed directly. ```python if __name__ == "__main__": main(CSV_FILE_PATH) ``` -------------------------------- ### Importing Required Libraries Source: https://developers.icproject.com/exporting-projects-to-csv The script begins by importing the necessary libraries: `csv`, `sys`, and `requests`. The `csv` library is used for writing data to a CSV file, `sys` is used for system-specific functionality, and `requests` is used to make HTTP requests to the IC Project API. ```python import csv import sys import requests ``` -------------------------------- ### Fetch Existing Projects Source: https://developers.icproject.com/importing-costs-from-csv-to-ic-project-using-python Retrieves existing projects from the IC Project API. ```python def get_existing_projects(api_url, headers): response = requests.get(f"{api_url}/projects", headers=headers) if response.status_code == 200: return {project['name']: project for project in response.json()} else: print(f"Error fetching projects: {response.status_code}") return {} ``` -------------------------------- ### Fetch Existing Tax Rates Source: https://developers.icproject.com/importing-costs-from-csv-to-ic-project-using-python Retrieves existing tax rates from the IC Project API. ```python def get_existing_tax_rates(api_url, headers): response = requests.get(f"{api_url}/finance/tax-rates", headers=headers) if response.status_code == 200: return {tax_rate['name']: tax_rate for tax_rate in response.json()} else: print(f"Error fetching tax rates: {response.status_code}") return {} ``` -------------------------------- ### Making API Requests to Create Projects Source: https://developers.icproject.com/creating-projects-with-csv-data Constructs the JSON payload and headers for the API request and sends a POST request to the IC Project API to create a project. ```python params = { "name": project_name, "dateStartPlanned": date_start, "dateEndPlanned": date_end, "category": None, "tags": None, "description": description, "isBlameableRemovalEnabled": True, "status": status, "budget": 0 } headers = { 'X-Auth-Token': authorization_token, 'Accept': 'application/json', 'Content-type': 'application/json' } response = requests.post( f"https://app.icproject.com/api/instance/{instance_slug}/project/projects", json=params, headers=headers, ) ``` -------------------------------- ### Project Created Source: https://developers.icproject.com/webhooks Payload for project.created webhook. ```json { "projectId": "bee567ff-d94c-4ca2-98ee-c0cb12846bdd", "name": "Project Name", "number": "123/abc", "shortCode": "qwerty", "status": "open" } ``` -------------------------------- ### Read CSV and Send Data Source: https://developers.icproject.com/how-to-import-contractors-to-ic-project-from-csv-using-python Reads the CSV file row by row, constructs contractor data dictionaries, and sends POST requests to the IC Project API to add contractors. ```python def main(csv_file): with open(csv_file, newline='', encoding='utf-8') as file: reader = csv.DictReader(file) for row in reader: contractor_data = { 'name': row['name'], # Required field: contractor's name # Optional fields below, uncomment if needed: # 'email': row['email'], # Optional: contractor's email # 'phoneNumber': row['phone'], # Optional: contractor's phone number # "fullName": "string", # Optional: full name # "vatId": "string", # Optional: VAT ID # "paymentDays": 0, # Optional: payment terms in days # "description": "string", # Optional: description # "tags": [ "497f6eca-6276-4993-bfeb-53cbbbba6f08" ], # Optional: tag IDs # "industryBranches": [ "497f6eca-6276-4993-bfeb-53cbbbba6f08" ], # Optional: industry branch IDs # "contactInfo": [ # { "type": "string", "value": "string", "isDefault": True } # Optional: contact information # ], } # Sending POST request to the API response = requests.post(API_ENDPOINT, json=contractor_data, headers=headers) if response.status_code == 201: print(f"Contractor {row['name']} added successfully.") else: print(f"Error adding contractor {row['name']}: {response.status_code}, {response.text}") ``` -------------------------------- ### Fetch Existing Cost Categories Source: https://developers.icproject.com/importing-costs-from-csv-to-ic-project-using-python Retrieves existing cost categories from the IC Project API. ```python def get_existing_cost_categories(api_url, headers): response = requests.get(f"{api_url}/finance/cost-categories", headers=headers) if response.status_code == 200: return {category['name']: category for category in response.json()} else: print(f"Error fetching cost categories: {response.status_code}") return {} ``` -------------------------------- ### Importing Required Libraries Source: https://developers.icproject.com/how-to-import-contractors-to-ic-project-from-csv-using-python Imports the `csv` module for reading CSV files and the `requests` module for making HTTP requests to the IC Project API. ```python import csv import requests ``` -------------------------------- ### Defining Columns for Export Source: https://developers.icproject.com/exporting-projects-to-csv The script defines the columns to export to the CSV file. Each column consists of a key, a label, and an optional value formatting function. The key represents the field name in the project data, the label is the column header in the CSV file, and the formatting function allows custom formatting of the values if needed. ```python columns = ( ('id', 'ID', None), ('no', 'Number', None), ('name', 'Name', None), # ... ) ``` -------------------------------- ### Task Created Source: https://developers.icproject.com/webhooks Payload for project.task.created webhook. ```json { "taskId": "9601bc47-b96b-486f-8600-c889befb950f", "name": "Task Name", "number": 1, "shortCode": "qwerty", "boardId": "dffea0ac-e3af-4b6d-8cd6-0eeef11395ed", "stageId": "92ad04f9-f50e-447d-8280-76e8d604eb3e", "projectId": "fd2b2218-0689-4e5a-8a25-0f724e379344", "weight": 1, "status": "in-preparation", "createdBy": "c74d11a9-5f4c-4ddd-94fa-399f759f6b4b" } ``` -------------------------------- ### Create New Tax Rate Source: https://developers.icproject.com/importing-costs-from-csv-to-ic-project-using-python Creates a new tax rate in IC Project if it does not already exist. ```python def create_tax_rate(name, value, api_url, headers): data = { "name": name, "value": value, "isDefault": False } response = requests.post(f"{api_url}/finance/tax-rates", headers=headers, json=data) if response.status_code == 201: return response.json() else: print(f"Error creating tax rate {name}: {response.status_code}, {response.text}") return None ``` -------------------------------- ### IC Project API Configuration Source: https://developers.icproject.com/export-orders-from-apilo-to-ic-project-and-create-tasks-using-python Configuration variables for connecting to the IC Project API. ```python IC_PROJECT_INSTANCE_SLUG = "YOUR_IC_PROJECT_INSTANCE_SLUG" IC_PROJECT_API_KEY = "YOUR_IC_PROJECT_API_KEY" IC_PROJECT_BOARD_LINK = "YOUR_IC_PROJECT_BOARD_LINK_WHERE_WE_WILL_ADD_TASKS" ``` -------------------------------- ### Import Required Libraries Source: https://developers.icproject.com/importing-costs-from-csv-to-ic-project-using-python Imports the necessary Python libraries for the script. ```python import csv import requests from datetime import datetime ``` -------------------------------- ### Board Created Source: https://developers.icproject.com/webhooks Payload for project.board.created webhook. ```json { "boardId": "df5239cf-2dfb-4e48-9bbf-391811473437", "shortCode": "qwerty", "name": "Board Name", "stageId": "addcecff-a25c-45c2-a9e7-f7c1dabaf07e", "projectId": "995e0d5d-2977-4174-8038-c26f6b365167", "weight": 1, "status": "in-preparation", "createdBy": "70398321-8466-4373-b440-6e0871267aed" } ``` -------------------------------- ### Task Data Structure Source: https://developers.icproject.com/export-orders-from-apilo-to-ic-project-and-create-tasks-using-python Defines the data structure for creating a task in IC Project, including identifier, column, name, description, dates, and priority. ```python task_data = { "identifier": str(uuid.uuid4()), "boardColumn": column_id, "name": f"Order ID: {order['idExternal']}", "description": f"Order from customer: {order['addressCustomer']['name']}", "dateStart": f"{order['createdAt']}", "dateEnd": "DATE END", "priority": "normal" } ``` -------------------------------- ### Stage Created Source: https://developers.icproject.com/webhooks Payload for project.stage.created webhook. ```json { "stageId": "922e62ea-7516-48ad-86a3-2304e0131929", "name": "Stage Name", "projectId": "29652a55-cb5c-4cd8-83c0-f95d2d1c5ffe", "weight": 1, "status": "in-preparation", "createdBy": "363952d4-c7e9-4596-9453-41dd8181ff01" } ``` -------------------------------- ### API Configuration Source: https://developers.icproject.com/export-orders-from-apilo-to-ic-project-and-create-tasks-using-python Python code snippet defining configuration variables for Apilo API access. ```python # Configuration for Apilo API APILO_INSTANCE_SLUG = "YOUR_APILO_INSTANCE_SLUG" APILO_ACCESS_TOKEN = "YOUR_APILO_ACCESS_TOKEN" ``` -------------------------------- ### Writing Project Data to CSV Source: https://developers.icproject.com/exporting-projects-to-csv The script opens a CSV file named ‘projects.csv’ in write mode using the `csv.writer` object. It writes the column headers to the file as the first row. Then, for each project in the API response, it extracts the relevant data based on the defined columns and writes a row to the CSV file. ```python with open('projects.csv', 'w', newline='') as csv_file: writer = csv.writer(csv_file, delimiter=',', quotechar='"') # Write column headers writer.writerow([k[1] for k in columns]) # Loop through projects for project in response.json(): # ... row = [] for key, label, formatter in columns: value = project[key] # Apply formatting if specified if formatter: value = formatter(value) row.append(value) writer.writerow(row) ``` -------------------------------- ### Extract Board Slug from URL Source: https://developers.icproject.com/export-orders-from-apilo-to-ic-project-and-create-tasks-using-python Function to extract the board slug from an IC Project board URL. ```python def get_board_slug(url): parts = url.rstrip('/').split('/') return parts[-1] ``` -------------------------------- ### Create Task in IC Project Source: https://developers.icproject.com/export-orders-from-apilo-to-ic-project-and-create-tasks-using-python Function to create a new task in IC Project based on order information. ```python def create_task_in_ic_project(order): url = f"https://app.icproject.com/api/instance/{IC_PROJECT_INSTANCE_SLUG}/project/task-templates" headers = { 'X-Auth-Token': IC_PROJECT_API_KEY, 'Content-Type': 'application/json', 'Accept': 'application/json', } try: response = requests.get(url, headers=headers) response.raise_for_status() # Raise an exception for HTTP errors except requests.RequestException as e: print(f"Error retrieving task templates: {e}") return board_slug = get_board_slug(IC_PROJECT_BOARD_LINK) column_id = get_board_column_id(board_slug) if not column_id: print(f"Error: Unable to find column for board_slug {board_slug}") return url = f"https://app.icproject.com/api/instance/{IC_PROJECT_INSTANCE_SLUG}/project/tasks" headers = { 'X-Auth-Token': IC_PROJECT_API_KEY, 'Accept': 'application/json', } ``` -------------------------------- ### Skipping the Header Row Source: https://developers.icproject.com/creating-projects-with-csv-data Advances the CSV reader past the first row, which is assumed to be a header. ```python next(reader, None) ``` -------------------------------- ### Handling Response and Errors Source: https://developers.icproject.com/creating-projects-with-csv-data Prints the HTTP status code of the API response and, if an error occurred (status code not 200), prints the response content for debugging. ```python print("\t", response.status_code) if response.status_code != 200: print(response.content) ``` -------------------------------- ### Create Task in IC Project Source: https://developers.icproject.com/export-orders-from-apilo-to-ic-project-and-create-tasks-using-python Handles the HTTP POST request to create a task in IC Project, including error handling and status code checking. ```python try: response = requests.post(url, json=task_data, headers=headers) response.raise_for_status() # Raise an exception for HTTP errors if response.status_code == 201: print(f"Task for order {order['idExternal']} created successfully.") else: print(f"Error creating task for order {order['idExternal']}: {response.status_code}") print(response.json()) except requests.RequestException as e: print(f"Error creating task: {e}") ``` -------------------------------- ### Create New Cost Category Source: https://developers.icproject.com/importing-costs-from-csv-to-ic-project-using-python Creates a new cost category in IC Project if it does not exist. ```python def create_cost_category(name, api_url, headers): data = { "name": name, } response = requests.post(f"{api_url}/finance/cost-categories", headers=headers, json=data) if response.status_code == 201: return response.json() else: print(f"Error creating cost category {name}: {response.status_code}, {response.text}") return None ``` -------------------------------- ### Task Moved Source: https://developers.icproject.com/webhooks Payload for project.task.moved webhook. ```json { "taskId": "46142593-166d-4d6c-8e41-f7f90e3d2978", "name": "Task Name", "number": 1, "shortCode": "qwerty", "boardId": "66867ee6-1830-4919-9208-6c5adca86964", "stageId": "b681c7f1-300b-49e5-a0bf-d0a12523850d", "projectId": "f1f52b79-a163-489a-98fb-b3dc2f852b12", "weight": 1, "status": "in-preparation", "boardColumnMovedFromId": "b4bfaa4a-0aa7-4544-b9e4-a1545bddca19", "moveCosts": true } ``` -------------------------------- ### Orchestration Function Source: https://developers.icproject.com/export-orders-from-apilo-to-ic-project-and-create-tasks-using-python The main function that orchestrates the integration process by fetching orders from Apilo and creating tasks in IC Project. ```python def integrate_apilo_with_ic_project(): orders = get_orders_from_apilo() for order in orders.get('orders', []): create_task_in_ic_project(order) ``` -------------------------------- ### Stage Updated Source: https://developers.icproject.com/webhooks Payload for project.stage.updated webhook. ```json { "stageId": "02e294a6-33bb-45d7-b95b-0fe627a8d8af", "name": "Stage Name", "projectId": "b680d260-9e72-4ab0-931b-74cbe19f7764", "weight": 1, "status": "in-preparation" } ``` -------------------------------- ### Send Cost Data to the API Source: https://developers.icproject.com/importing-costs-from-csv-to-ic-project-using-python This function iterates through the prepared cost data and sends each cost item to the IC Project API using a POST request. It includes basic error handling and success messages. ```python def send_costs_to_api(costs, api_url, headers): for cost in costs: response = requests.post(f"{api_url}/finance/costs", headers=headers, json=cost) if response.status_code == 201: print(f"Success: Cost {cost['name']} was sent.") else: print(f"Error: Failed to send cost {cost['name']}. Response code: {response.status_code}, error: {response.text}") ``` -------------------------------- ### Fetch Orders from Apilo Source: https://developers.icproject.com/export-orders-from-apilo-to-ic-project-and-create-tasks-using-python Function to retrieve orders from the Apilo API. ```python def get_orders_from_apilo(): url = f"https://{APILO_INSTANCE_SLUG}.apilo.com/rest/api/orders" headers = { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': f"Bearer {APILO_ACCESS_TOKEN}", } try: response = requests.get(url, headers=headers) response.raise_for_status() # Raise an exception for HTTP errors return response.json() except requests.RequestException as e: print(f"Error retrieving orders: {e}") return {} ``` -------------------------------- ### Integration Function Source: https://developers.icproject.com/export-orders-from-apilo-to-ic-project-and-create-tasks-using-python This is the main function to run the integration between Apilo and IC Project. ```python integrate_apilo_with_ic_project() ``` -------------------------------- ### Task Updated Source: https://developers.icproject.com/webhooks Payload for project.task.updated webhook. ```json { "taskId": "9524fc4d-b004-44cf-b633-7bc7971daa0b", "name": "Task Name", "number": 1, "shortCode": "qwerty", "boardId": "97c0cc88-6b12-4285-a965-81497beca4d1", "stageId": "c17581b9-f88a-405f-a3f8-feb9ca11f845", "projectId": "8a52af57-7527-4cd2-aca2-3b85470445d5", "weight": 1, "status": "in-preparation" } ``` -------------------------------- ### Board Updated Source: https://developers.icproject.com/webhooks Payload for project.board.updated webhook. ```json { "boardId": "af785a28-65fd-4166-9066-d0bebec27b1e", "shortCode": "qwerty", "name": "Board Name", "stageId": "9a776825-b990-4c0f-9766-24f62637f19a", "projectId": "8f776e0b-fd8f-4600-bd8d-9992839d64d6", "weight": 1, "status": "in-preparation" } ``` -------------------------------- ### Project User Assigned Source: https://developers.icproject.com/webhooks Payload for project.users.assigned webhook. ```json { "projectId": "23d18255-34aa-49bc-baea-7842e16a429b", "userId": "eb004a65-86bc-416a-9d91-dd9219ea8032", "role": "none", "hourlyRate": 0.0 } ``` -------------------------------- ### Project User Unassigned Source: https://developers.icproject.com/webhooks Payload for project.users.unassigned webhook. ```json { "projectId": "0d8dca2b-d2b9-4b16-bc0e-5be3c176c946", "userId": "4f7b12fe-9d07-49b5-a439-176cc6e6af34" } ``` -------------------------------- ### Project Deleted Source: https://developers.icproject.com/webhooks Payload for project.deleted webhook. ```json { "projectId": "2d88adc3-fb4d-447e-a0dc-00da492fe35e" } ``` -------------------------------- ### Board User Assigned Source: https://developers.icproject.com/webhooks Payload for project.board.users.assigned webhook. ```json { "projectId": "85776e13-9326-444d-9529-f8b32b9346fb", "userId": "4cdbfa4d-c456-4aa9-a9bb-bac80cbf7a2e", "boardId": "8e74eda0-e64f-46cc-aa7c-0377b9dec561" } ``` -------------------------------- ### Board Deleted Source: https://developers.icproject.com/webhooks Payload for project.board.deleted webhook. ```json { "boardId": "6fad96ed-abca-4953-b2fc-cc667a752db8", "projectId": "8ce3f808-b6f0-4542-90b2-ce48cf8b348d" } ``` -------------------------------- ### Stage Deleted Source: https://developers.icproject.com/webhooks Payload for project.stage.deleted webhook. ```json { "stageId": "3d76d1c8-c013-4e2d-94ba-2a21d279a63c", "projectId": "6ec46b75-87ad-4b74-a938-e206fadc4fe0" } ``` -------------------------------- ### Checking Response Status Code Source: https://developers.icproject.com/exporting-projects-to-csv After making the API request, the script checks the response status code to ensure the request was successful. If the status code is not 200 (indicating a successful response), an error message is printed, and the script exits. ```python if response.status_code != 200: print(response.status_code, response.content) sys.exit() ``` -------------------------------- ### Convert CSV Data to JSON Format Source: https://developers.icproject.com/importing-costs-from-csv-to-ic-project-using-python This function processes a CSV file, checks for existing cost categories, tax rates, and projects in the IC Project API, and creates new ones if necessary. It then structures the data into a JSON format suitable for API submission. ```python def csv_to_costs(file_path, api_url, headers): existing_categories = get_existing_cost_categories(api_url, headers) existing_tax_rates = get_existing_tax_rates(api_url, headers) existing_projects = get_existing_projects(api_url, headers) costs = [] with open(file_path, mode='r', encoding='utf-8') as file: csv_reader = csv.DictReader(file) for row in csv_reader: category_name = row['category'] if category_name not in existing_categories: new_category = create_cost_category(category_name, api_url, headers) if new_category: existing_categories[category_name] = new_category cost_category = existing_categories.get(category_name, {}) tax_rate_name = row['taxRate'] tax_rate_value = float(row['taxRateValue']) if tax_rate_name not in existing_tax_rates: new_tax_rate = create_tax_rate(tax_rate_name, tax_rate_value, api_url, headers) if new_tax_rate: existing_tax_rates[tax_rate_name] = new_tax_rate tax_rate = existing_tax_rates.get(tax_rate_name, {}) project_name = row.get('project', '') project_id = existing_projects.get(project_name, {}).get('id') if project_name else None cost = { "name": row['name'], "description": row['description'], "priceNet": float(row['priceNet']), "priceGross": float(row['priceGross']), "date": row['date'], "isBilled": row['isBilled'].lower() == 'true', "isPosted": row['isPosted'].lower() == 'true', "createdAt": datetime.now().isoformat(), "updatedAt": datetime.now().isoformat(), "costCategory": cost_category.get('id'), "taxRate": tax_rate.get('id'), "financeProject": project_id } costs.append(cost) return costs ``` -------------------------------- ### Task Deleted Source: https://developers.icproject.com/webhooks Payload for project.task.deleted webhook. ```json { "taskId": "065d384d-5c0d-4ef6-a00a-2a265c20237e", "projectId": "fb0ffabf-0e68-461b-941f-16113dfe22f5" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.