### Get List Entries - Node.js Example Source: https://developer.affinity.co/docs/v2/index Example code in Node.js to make a GET request to the Affinity API for fetching list entries. This snippet utilizes the 'axios' library for HTTP requests. Replace placeholders for company ID and token. ```javascript const axios = require('axios'); const companyId = '{companyId}'; const cursor = 'ICAgICAgYmVmb3JlOjo6Nw'; const limit = 100; const token = ''; axios.get(`https://api.affinity.co/v2/companies/${companyId}/list-entries`, { params: { cursor: cursor, limit: limit }, headers: { 'Authorization': `Bearer ${token}` } }) .then(response => { console.log('Data:', response.data); }) .catch(error => { console.error('Error:', error); }); ``` -------------------------------- ### Get All Opportunities (Node.js) Source: https://developer.affinity.co/docs/v2/index This Node.js example shows how to retrieve a paginated list of opportunities using the 'affinity-api' library. It demonstrates making a GET request to the opportunities endpoint with optional query parameters. ```javascript const affinity = require('affinity-api'); const client = affinity.createClient({ token: '' }); client.get('/opportunities', { params: { cursor: 'ICAgICAgYmVmb3JlOjo6Nw', limit: 100, ids: [1, 2] } }) .then(response => { console.log(response.data); }) .catch(error => { console.error(error); }); ``` -------------------------------- ### Get All Opportunities (Ruby) Source: https://developer.affinity.co/docs/v2/index This Ruby example shows how to retrieve opportunities using the 'affinity' gem. It demonstrates initializing the client and performing a GET request to the opportunities endpoint, including parameters for cursor, limit, and filtering by IDs. ```ruby require 'affinity' client = Affinity::Client.new(token: '') response = client.get('/opportunities', params: { cursor: 'ICAgICAgYmVmb3JlOjo6Nw', limit: 100, ids: [1, 2] }) puts response.data ``` -------------------------------- ### Get Note Replies (Ruby) Source: https://developer.affinity.co/docs/v2/index This Ruby example shows how to fetch note replies using the 'affinity' gem. It demonstrates initializing the client with an authentication token and performing a GET request to the notes replies endpoint with query parameters. ```ruby require 'affinity' client = Affinity::Client.new(token: '') response = client.get('/v2/notes/{noteId}/replies', params: { filter: 'string', cursor: 'string', limit: 20, totalCount: false }) puts response.data ``` -------------------------------- ### Get Note Replies (Node.js) Source: https://developer.affinity.co/docs/v2/index This Node.js example shows how to fetch replies for a note using the 'affinity-api' library. It requires setting up an API client with your authentication token and making a GET request to the relevant endpoint. ```javascript const affinity = require('affinity-api'); const client = affinity.createClient({ token: '' }); client.get(`/v2/notes/{noteId}/replies`, { params: { filter: 'string', cursor: 'string', limit: 20, totalCount: false } }) .then(response => { console.log(response.data); }) .catch(error => { console.error(error); }); ``` -------------------------------- ### Get Replies for a Note (Node.js) Source: https://developer.affinity.co/docs/v2/index Node.js example for retrieving replies for a given note. It shows how to construct the API request URL, including optional filter and pagination parameters, and how to handle the authenticated GET request. ```javascript const fetch = require('node-fetch'); async function getNoteReplies(noteId, token, options = {}) { const params = new URLSearchParams(options).toString(); const url = `https://api.affinity.co/v2/notes/${noteId}/replies${params ? '?' + params : ''}`; const response = await fetch(url, { method: 'GET', headers: { 'Authorization': `Bearer ${token}` } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return response.json(); } // Example usage: // const noteId = 123; // const token = 'YOUR_TOKEN_HERE'; // getNoteReplies(noteId, token, { filter: 'creator.id=1', limit: 20 }).then(data => console.log(data)).catch(error => console.error(error)); ``` -------------------------------- ### Filtering Syntax Examples Source: https://developer.affinity.co/docs/v2/index Demonstrates the usage of various operators and boolean logic for filtering data. Includes examples for simple types like exact match, starts with, ends with, contains, numerical comparisons, null/empty checks, and negation. Also shows collection filtering with ordering, containment, emptiness, and negation. Spaces and special characters handling is illustrated. ```text content = "hello world" content=hello content =^ he content =$ llo content =~ lo count > 1 content >= 1 count < 1 content <= 1 content != * content = * content = "" !(content = "hello world") !(content =^ "hello world") industries = [Healthcare,Fintech] industries =~ [Healthcare,Fintech] industries =[] !(industries = [Healthcare,Fintech]) foo = 1 | baz = 2 & bar = 3 (foo = 1 | baz = 2) & bar = 3 ``` -------------------------------- ### Get Meetings with Node.js Source: https://developer.affinity.co/docs/v2/index Example of how to retrieve a list of meetings using Node.js. This demonstrates making a GET request to the meetings endpoint with appropriate headers and query parameters. ```javascript // Node.js request example would go here, using a library like 'axios' or 'node-fetch' ``` -------------------------------- ### GET Person List Entries with Ruby Source: https://developer.affinity.co/docs/v2/index A Ruby example using the `httparty` gem to make a GET request to the Affinity API for person list entries. It demonstrates setting up headers and parameters for the request. ```ruby require 'httparty' person_id = '{personId}' # Replace with the actual person ID token = '' # Replace with your Bearer token cursor = 'ICAgICAgYmVmb3JlOjo6Nw' # Optional: cursor for pagination limit = 100 # Optional: limit for results url = "https://api.affinity.co/v2/persons/#{person_id}/list-entries" response = HTTParty.get(url, headers: { 'Authorization' => "Bearer #{token}" }, query: { cursor: cursor, limit: limit } ) if response.code == 200 puts "Success: #{JSON.pretty_generate(response.parsed_response)}" else puts "Error: #{response.code} - #{response.body}" end ``` -------------------------------- ### User Guides - Opportunity Data Source: https://developer.affinity.co/docs/v2/index Guide on retrieving Opportunity data. ```APIDOC ## User Guides - Opportunity Data ### Description Retrieve Opportunity data. ### Endpoints - GET `/v2/opportunities` - This endpoint only returns Opportunity names and List IDs. - GET `/v2/lists/{listId}/list-entries` (for an Opportunity List) - For comprehensive Opportunity data, use this endpoint when the list is of type Opportunity. ``` -------------------------------- ### Get List Entries Example (JSON) Source: https://developer.affinity.co/docs/v2/index An example JSON response for retrieving entries within a specific list. It showcases the structure of returned 'data' objects, including 'id', 'name', 'type', 'isPublic', 'ownerId', and 'creatorId'. ```json { "data": [ { "id": 1, "name": "My Companies", "type": "company", "isPublic": false, "ownerId": 1, "creatorId": 1 }, { "id": 2, "name": "My Persons", "type": "person", "isPublic": false, "ownerId": 1, "creatorId": 1 }, { "id": 3, "name": "My Opportunities", "type": "opportunity", "isPublic": false, "ownerId": 1, "creatorId": 1 } ], "pagination": { "prevUrl": "https://api.affinity.co/v2/lists?cursor=ICAgICAgYmVmb3JlOjo6Nw", "nextUrl": "https://api.affinity.co/v2/lists?cursor=ICAgICAgIGFmdGVyOjo6NA" } } ``` -------------------------------- ### Retrieve Opportunities with Pagination (Ruby) Source: https://developer.affinity.co/docs/v2/index Fetches a paginated list of opportunities using Ruby. Requires an Authorization header with a Bearer token. This example demonstrates making the GET request. ```ruby require 'open-uri' require 'json' url = 'https://api.affinity.co/v2/opportunities?cursor=ICAgICAgYmVmb3JlOjo6Nw&limit=100&ids=1' headers = { 'Authorization': 'Bearer ' } response = URI.open(url, headers).read puts JSON.parse(response) ``` -------------------------------- ### List All Company Merge Tasks - Ruby Source: https://developer.affinity.co/docs/v2/index A Ruby example demonstrating how to fetch a paginated list of company merge tasks via the Affinity API. This snippet uses the `net/http` library to construct and send a GET request, including authorization headers and query parameters. ```ruby require 'net/http' require 'uri' def list_company_merge_tasks(token, cursor = nil, limit = 100, filter = nil) uri = URI.parse("https://api.affinity.co/v2/tasks/company-merges") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Get.new(uri.request_uri) request['Authorization'] = "Bearer #{token}" query_params = { 'limit' => limit } query_params['cursor'] = cursor if cursor query_params['filter'] = filter if filter uri.query = URI.encode_www_form(query_params) request.uri = uri response = http.request(request) JSON.parse(response.body) end ``` -------------------------------- ### Retrieve Opportunities with Pagination (Node.js) Source: https://developer.affinity.co/docs/v2/index Fetches a paginated list of opportunities using Node.js. Requires an Authorization header with a Bearer token. This example demonstrates making the GET request. ```javascript const fetch = require('node-fetch'); const options = { method: 'GET', headers: { 'Authorization': 'Bearer ' } }; fetch('https://api.affinity.co/v2/opportunities?cursor=ICAgICAgYmVmb3JlOjo6Nw&limit=100&ids=1', options) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err)); ``` -------------------------------- ### Fetch Person Notes using Node.js Source: https://developer.affinity.co/docs/v2/index This Node.js example shows how to make an API request to fetch notes for a person. It utilizes the 'axios' library for making HTTP requests and includes the Authorization header for authentication. The example assumes you have the 'axios' library installed. ```javascript const axios = require('axios'); const options = { method: 'GET', url: 'https://api.affinity.co/v2/persons/{personId}/notes', params: { filter: 'string', cursor: 'string', limit: '20', totalCount: 'false' }, headers: { Authorization: 'Bearer ' } }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### GET Person List Entries with Node.js Source: https://developer.affinity.co/docs/v2/index Example of retrieving list entries for a person using Node.js and the `axios` library. This code shows how to set up the request with headers and parameters, handling the response. ```javascript const axios = require('axios'); const personId = '{personId}'; // Replace with the actual person ID const token = ''; // Replace with your Bearer token const cursor = 'ICAgICAgYmVmb3JlOjo6Nw'; // Optional: cursor for pagination const limit = 100; // Optional: limit for results axios.get(`https://api.affinity.co/v2/persons/${personId}/list-entries`, { headers: { 'Authorization': `Bearer ${token}` }, params: { cursor: cursor, limit: limit } }) .then(response => { console.log('Success:', JSON.stringify(response.data, null, 2)); }) .catch(error => { console.error('Error:', error); }); ``` -------------------------------- ### Get Company Lists Request Example (Python) Source: https://developer.affinity.co/docs/v2/index This Python snippet demonstrates fetching lists for a given company using the 'requests' library. It constructs the API URL with the company ID and includes the necessary authorization token in the request headers. ```python import requests company_id = '{companyId}' token = '' headers = { 'Authorization': f'Bearer {token}' } response = requests.get(f'https://api.affinity.co/v2/companies/{company_id}/lists?cursor=ICAgICAgYmVmb3JlOjo6Nw&limit=100', headers=headers) print(response.json()) ``` -------------------------------- ### Get All Person Merges Response Example (JSON) Source: https://developer.affinity.co/docs/v2/index An example JSON response for retrieving person merges, showcasing successful and failed merge states, along with pagination details. Includes data on merge ID, status, task ID, timestamps, person IDs, and completion messages. ```json { "data": [ { "id": 12, "status": "success", "taskId": "789e0123-e45b-67c8-d901-234567890123", "startedAt": "2025-06-03T10:30:00Z", "primaryPersonId": 12345, "duplicatePersonId": 67890, "completedAt": "2025-06-03T10:32:15Z", "errorMessage": null }, { "id": 13, "status": "failed", "taskId": "456e7890-1234-5678-9012-345678901234", "startedAt": "2025-06-03T09:15:00Z", "primaryPersonId": 54321, "duplicatePersonId": 98765, "completedAt": "2025-06-03T09:16:30Z", "errorMessage": "Primary person not found" } ], "pagination": { "nextUrl": "https://api.affinity.co/v2/persons/merge?cursor=eyJpZCI6NDU2ZTc4OTAtZTEyYi0zNGM1LWQ2NzgtOTAxMjM0NTY3ODkwfQ==", "prevUrl": null } } ``` -------------------------------- ### List All Company Merge Tasks - Node.js Source: https://developer.affinity.co/docs/v2/index Example of how to fetch a paginated list of company merge tasks using Node.js. This snippet demonstrates making a GET request to the Affinity API, including query parameters for filtering and pagination. Assumes the use of a fetch-like library. ```javascript async function listCompanyMergeTasks(token, cursor, limit, filter) { const queryParams = new URLSearchParams({ cursor: cursor, limit: limit, filter: filter }); const response = await fetch(`https://api.affinity.co/v2/tasks/company-merges?${queryParams}`, { method: 'GET', headers: { 'Authorization': `Bearer ${token}` } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return await response.json(); } ``` -------------------------------- ### Retrieve All Lists (Node.js) Source: https://developer.affinity.co/docs/v2/index Example Node.js code to fetch a paginated list of all accessible lists using the Affinity API. This snippet demonstrates making a GET request with an authorization header. ```javascript const axios = require('axios'); const options = { method: 'GET', url: 'https://api.affinity.co/v2/lists', params: { cursor: 'ICAgICAgYmVmb3JlOjo6Nw', limit: '100' }, headers: { Authorization: 'Bearer ' } }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Retrieve Opportunity Notes with Node.js Source: https://developer.affinity.co/docs/v2/index This Node.js example shows how to make a GET request to the Affinity API to fetch notes for an opportunity. It utilizes the 'axios' library for making HTTP requests and includes headers for authorization and content type. ```javascript const axios = require('axios'); const getOpportunityNotes = async (opportunityId, authToken) => { try { const response = await axios.get( `https://api.affinity.co/v2/opportunities/${opportunityId}/notes`, { headers: { 'Authorization': `Bearer ${authToken}`, 'Content-Type': 'application/json' }, params: { limit: 20, totalCount: false } } ); return response.data; } catch (error) { console.error('Error fetching opportunity notes:', error); throw error; } }; // Example usage: // const opportunityId = 'YOUR_OPPORTUNITY_ID'; // const authToken = 'YOUR_TOKEN_HERE'; // getOpportunityNotes(opportunityId, authToken).then(data => console.log(data)).catch(err => console.error(err)); ``` -------------------------------- ### Get All Persons with Field Data (Python) Source: https://developer.affinity.co/docs/v2/index This Python example shows how to fetch a paginated list of persons, with options to include specific field data. It outlines the construction of the request URL with various query parameters and the necessary authorization header. ```python import requests def get_all_persons(token, cursor=None, limit=100, ids=None, field_ids=None, field_types=None): """Fetches a paginated list of persons from the Affinity API. Args: token (str): Your API Bearer token. cursor (str, optional): Cursor for pagination. Defaults to None. limit (int, optional): Number of items per page. Defaults to 100. ids (list, optional): List of person IDs. Defaults to None. field_ids (list, optional): List of field IDs for data retrieval. Defaults to None. field_types (list, optional): List of field types for data retrieval. Defaults to None. Returns: dict: The JSON response from the API. """ base_url = "https://api.affinity.co/v2/persons" params = {} if cursor: params['cursor'] = cursor params['limit'] = limit if ids: params['ids'] = ids if field_ids: params['fieldIds'] = field_ids if field_types: params['fieldTypes'] = field_types headers = { 'Authorization': f'Bearer {token}' } try: response = requests.get(base_url, headers=headers, params=params) response.raise_for_status() # Raise an exception for bad status codes return response.json() except requests.exceptions.RequestException as e: print(f"Error fetching persons: {e}") return None # Example usage: # token = '' # persons_data = get_all_persons( # token=token, # limit=50, # field_types=['enriched', 'global'] # ) # if persons_data: # print(persons_data) ``` -------------------------------- ### Fetch List Entry Field Data (Ruby) Source: https://developer.affinity.co/docs/v2/index This Ruby example shows how to make a GET request to retrieve a specific field's data from a list entry. It utilizes the list ID, list entry ID, and field ID in the URL and includes the API token for authentication. ```ruby require 'net/http' require 'uri' list_id = '{listId}' list_entry_id = '{listEntryId}' field_id = '{fieldId}' token = '' uri = URI.parse("https://api.affinity.co/v2/lists/#{list_id}/list-entries/#{list_entry_id}/fields/#{field_id}") request = Net::HTTP::Get.new(uri) request['Authorization'] = "Bearer #{token}" response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| http.request(request) end puts response.body ``` -------------------------------- ### Get Company Merge Status (Node.js) Source: https://developer.affinity.co/docs/v2/index This Node.js snippet shows how to retrieve the status of a company merge using 'axios'. It sends a GET request to the specified endpoint, requiring the merge ID and authentication token. Ensure 'axios' is installed (`npm install axios`). ```javascript const axios = require('axios'); const getCompanyMergeStatus = async (mergeId) => { try { const response = await axios.get(`https://api.affinity.co/v2/company-merges/${mergeId}`, { headers: { 'Authorization': 'Bearer ' } }); console.log('Company merge status:', response.data); } catch (error) { console.error('Error fetching company merge status:', error.response ? error.response.data : error.message); } }; getCompanyMergeStatus('YOUR_MERGE_ID_HERE'); ``` -------------------------------- ### Fetch List Entries - Python Example Source: https://developer.affinity.co/docs/v2/index A Python script demonstrating how to retrieve list entries from the Affinity API using the 'requests' library. It shows how to set up the request with parameters and authorization headers. Remember to substitute your actual company ID and API token. ```python import requests company_id = '{companyId}' cursor = 'ICAgICAgYmVmb3JlOjo6Nw' limit = 100 token = '' url = f'https://api.affinity.co/v2/companies/{company_id}/list-entries' params = { 'cursor': cursor, 'limit': limit } headers = { 'Authorization': f'Bearer {token}' } response = requests.get(url, params=params, headers=headers) if response.status_code == 200: print('Data:', response.json()) else: print('Error:', response.status_code, response.text) ``` -------------------------------- ### Get Company Merge Status (Python) Source: https://developer.affinity.co/docs/v2/index This Python script retrieves the status of a company merge using the 'requests' library. It sends a GET request to the API endpoint with the merge ID and authentication token. Make sure the 'requests' library is installed (`pip install requests`). ```python import requests url = "https://api.affinity.co/v2/company-merges/{mergeId}".format(mergeId='YOUR_MERGE_ID_HERE') headers = { "Authorization": "Bearer " } try: response = requests.get(url, headers=headers) response.raise_for_status() # Raise an exception for bad status codes print("Company merge status:", response.json()) except requests.exceptions.RequestException as e: print(f"Error fetching company merge status: {e}") if hasattr(e, 'response') and e.response is not None: print(f"Response body: {e.response.text}") ``` -------------------------------- ### Get All Opportunities (Python) Source: https://developer.affinity.co/docs/v2/index This Python snippet demonstrates how to fetch opportunities using the 'affinity' library. It involves initializing the client and making a GET request to the opportunities endpoint with query parameters for pagination and filtering by IDs. ```python import affinity client = affinity.Client(token='') response = client.get('/opportunities', params={ 'cursor': 'ICAgICAgYmVmb3JlOjo6Nw', 'limit': 100, 'ids': [1, 2] }) print(response.data) ``` -------------------------------- ### Get Meetings with Python Source: https://developer.affinity.co/docs/v2/index Example of how to retrieve a list of meetings using Python. This shows how to use the 'requests' library to send a GET request to the meetings endpoint. ```python # Python request example would go here, using the 'requests' library ``` -------------------------------- ### Get Person Merge Status (Ruby Request) Source: https://developer.affinity.co/docs/v2/index Example Ruby code using `net/http` to get the status of a person merge. It constructs the URL with the `mergeId` and includes the Authorization header. ```ruby require 'net/http' require 'uri' require 'json' token = 'YOUR_TOKEN_HERE' merge_id = 'YOUR_MERGE_ID' # Replace with the actual mergeId uri = URI.parse("https://api.affinity.co/v2/person-merges/#{merge_id}") request = Net::HTTP::Get.new(uri.request_uri) request['Authorization'] = "Bearer #{token}" response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| http.request(request) end if response.code == '200' puts "Person merge details: #{response.body}" else puts "Error fetching merge details: #{response.code} - #{response.body}" end ``` -------------------------------- ### User Guides - List Entries Source: https://developer.affinity.co/docs/v2/index Guide on retrieving Company, Person, or Opportunity rows from a List. ```APIDOC ## User Guides - List Entries ### Description Retrieve Company, Person, or Opportunity rows from a List. ### Method GET ### Endpoint `/v2/lists/{listId}/list-entries` ### Parameters #### Path Parameters - **listId** (string) - Required - The ID of the list. ``` -------------------------------- ### Get Persons Attached to a Note (Ruby) Source: https://developer.affinity.co/docs/v2/index Ruby implementation for retrieving attached persons to a note. This example utilizes the 'httparty' gem to make the HTTP GET request with necessary authentication and query parameters. ```ruby require 'httparty' def get_attached_persons(note_id, token, options = {}) url = "https://api.affinity.co/v2/notes/#{note_id}/attached-persons" response = HTTParty.get(url, query: options, headers: { 'Authorization' => "Bearer #{token}" }) response.parsed_response end # Example usage: # note_id = 123 # token = 'YOUR_TOKEN_HERE' # opts = { totalCount: false, limit: 20 } # data = get_attached_persons(note_id, token, opts) # puts data ``` -------------------------------- ### Get All Opportunities Source: https://developer.affinity.co/docs/v2/index Fetches a list of all opportunities within the system. This endpoint provides a comprehensive view of all sales opportunities. ```http GET /v2/opportunities ``` -------------------------------- ### Get List Fields Metadata (Ruby) Source: https://developer.affinity.co/docs/v2/index This Ruby example shows how to fetch metadata for fields belonging to a specific list. It makes a GET request to the API, including the list ID and authorization token. ```ruby require 'net/http' require 'uri' list_id = '{listId}' token = '' uri = URI.parse("https://api.affinity.co/v2/lists/#{list_id}/fields") request = Net::HTTP::Get.new(uri) request['Authorization'] = "Bearer #{token}" response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| http.request(request) end puts response.body ``` -------------------------------- ### Initiate Company Merge (Python) Source: https://developer.affinity.co/docs/v2/index This Python script demonstrates how to initiate a company merge using the 'requests' library. It constructs a POST request to the Affinity API, including the authentication token and the merge payload. Make sure to install the 'requests' library (`pip install requests`). ```python import requests import json url = "https://api.affinity.co/v2/company-merges" headers = { "Authorization": "Bearer ", "Content-Type": "application/json" } payload = { "primaryCompanyId": 12345, "duplicateCompanyId": 67890 } try: response = requests.post(url, headers=headers, data=json.dumps(payload)) response.raise_for_status() # Raise an exception for bad status codes print("Company merge initiated:", response.json()) except requests.exceptions.RequestException as e: print(f"Error initiating company merge: {e}") if hasattr(e, 'response') and e.response is not None: print(f"Response body: {e.response.text}") ``` -------------------------------- ### Initiate Company Merge (Ruby) Source: https://developer.affinity.co/docs/v2/index This Ruby code snippet shows how to initiate a company merge using the 'net/http' library. It sends a POST request to the Affinity API with the required headers and the JSON payload containing company IDs. This example assumes you have your API token readily available. ```ruby require 'net/http' require 'uri' require 'json' uri = URI.parse('https://api.affinity.co/v2/company-merges') http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Post.new(uri.request_uri) request['Authorization'] = 'Bearer ' request['Content-Type'] = 'application/json' request.body = { primaryCompanyId: 12345, duplicateCompanyId: 67890 }.to_json begin response = http.request(request) puts "Company merge initiated: #{response.body}" rescue StandardError => e puts "Error initiating company merge: #{e.message}" end ``` -------------------------------- ### Get Persons Attached to a Note (Node.js) Source: https://developer.affinity.co/docs/v2/index Example for retrieving persons attached to a note using Node.js. This demonstrates making a GET request to the Affinity API with appropriate headers and query parameters for pagination and filtering. ```javascript const fetch = require('node-fetch'); async function getAttachedPersons(noteId, token, options = {}) { const params = new URLSearchParams(options).toString(); const url = `https://api.affinity.co/v2/notes/${noteId}/attached-persons${params ? '?' + params : ''}`; const response = await fetch(url, { method: 'GET', headers: { 'Authorization': `Bearer ${token}` } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return response.json(); } // Example usage: // const noteId = 123; // const token = 'YOUR_TOKEN_HERE'; // getAttachedPersons(noteId, token, { totalCount: false, limit: 20 }).then(data => console.log(data)).catch(error => console.error(error)); ``` -------------------------------- ### Initiate Person Merge (Ruby Request) Source: https://developer.affinity.co/docs/v2/index Example Ruby code using the `net/http` library to initiate a person merge. It sets up the request, including headers and the JSON payload, and sends it to the API. ```ruby require 'net/http' require 'uri' require 'json' token = 'YOUR_TOKEN_HERE' primary_person_id = 12345 duplicate_person_id = 67890 uri = URI.parse('https://api.affinity.co/v2/person-merges') request = Net::HTTP::Post.new(uri.request_uri) request['Authorization'] = "Bearer #{token}" request['Content-Type'] = 'application/json' request.body = { primaryPersonId: primary_person_id, duplicatePersonId: duplicate_person_id }.to_json response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| http.request(request) end if response.code == '202' puts "Merge task initiated: #{response.body}" else puts "Error initiating merge: #{response.code} - #{response.body}" end ``` -------------------------------- ### Get List Fields Metadata (Node.js) Source: https://developer.affinity.co/docs/v2/index This Node.js example shows how to fetch metadata for fields associated with a given list. It makes a GET request to the API endpoint, including the list ID and authorization token. ```javascript const fetch = require('node-fetch'); const listId = '{listId}'; const token = ''; fetch(`https://api.affinity.co/v2/lists/${listId}/fields`, { method: 'GET', headers: { 'Authorization': `Bearer ${token}` } }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Retrieve List Entries - Ruby Example Source: https://developer.affinity.co/docs/v2/index This Ruby code snippet illustrates how to fetch list entries using the 'Net::HTTP' library. It constructs the request with necessary parameters and authorization. Ensure you replace the placeholder values for your company ID and API token. ```ruby require 'net/http' require 'uri' company_id = '{companyId}' cursor = 'ICAgICAgYmVmb3JlOjo6Nw' limit = 100 token = '' uri = URI.parse("https://api.affinity.co/v2/companies/#{company_id}/list-entries?cursor=#{cursor}&limit=#{limit}") request = Net::HTTP::Get.new(uri) request['Authorization'] = "Bearer #{token}" response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(request) end if response.code == '200' puts "Data: #{response.body}" else puts "Error: #{response.code} #{response.body}" end ``` -------------------------------- ### Get List Metadata (Node.js) Source: https://developer.affinity.co/docs/v2/index Node.js example for fetching metadata of a specific list using its ID. This code makes a GET request to the Affinity API, including the `listId` in the URL and the authorization token in the headers. ```javascript const axios = require('axios'); const options = { method: 'GET', url: 'https://api.affinity.co/v2/lists/{listId}', headers: { Authorization: 'Bearer ' } }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### User Guides - Saved View List Entries Source: https://developer.affinity.co/docs/v2/index Guide on retrieving Company, Person, or Opportunity rows from a Saved View. ```APIDOC ## User Guides - Saved View List Entries ### Description Retrieve Company, Person, or Opportunity rows from a Saved View, respecting configured fields and filters. ### Method GET ### Endpoint `/v2/lists/{listId}/saved-views/{viewId}/list-entries` ### Parameters #### Path Parameters - **listId** (string) - Required - The ID of the list. - **viewId** (string) - Required - The ID of the saved view. ``` -------------------------------- ### Get Meetings with Ruby Source: https://developer.affinity.co/docs/v2/index Example of how to retrieve a list of meetings using Ruby. This illustrates making a GET request to the meetings endpoint using Ruby's built-in Net::HTTP library or a gem like 'httparty'. ```ruby # Ruby request example would go here, using Net::HTTP or a gem ``` -------------------------------- ### User Guides - Full Rolodex Source: https://developer.affinity.co/docs/v2/index Guide on retrieving the full rolodex of Companies or Persons in Affinity. ```APIDOC ## User Guides - Full Rolodex ### Description Retrieve the full rolodex of Companies or Persons available in Affinity. ### Endpoints - GET `/v2/companies` - GET `/v2/persons` ### Notes Data from list-specific Fields will not be returned by these endpoints. ``` -------------------------------- ### Get All Opportunities (cURL) Source: https://developer.affinity.co/docs/v2/index This cURL command demonstrates how to paginate through opportunities in Affinity. It includes the GET request to the opportunities endpoint and shows optional query parameters such as cursor, limit, and ids. ```curl curl -X GET \ 'https://api.affinity.co/opportunities?cursor=ICAgICAgYmVmb3JlOjo6Nw&limit=100&ids=1&ids=2' \ -H 'Authorization: Bearer ' ``` -------------------------------- ### Get Single List Entry without Field Data (curl) Source: https://developer.affinity.co/docs/v2/index This example demonstrates how to retrieve a list entry without any associated field data by omitting the 'fieldIds' and 'fieldTypes' parameters. It shows the basic GET request structure. ```curl curl -X GET "https://api.affinity.co/v2/lists/{listId}/list-entries/{listEntryId}" \ -H "accept: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" ``` -------------------------------- ### Get Specific Company Merge Task - Node.js Source: https://developer.affinity.co/docs/v2/index Node.js code to fetch details of a specific company merge task using its ID. This example uses `fetch` to make a GET request to the Affinity API, requiring an authentication token. ```javascript async function getCompanyMergeTask(token, taskId) { const response = await fetch(`https://api.affinity.co/v2/tasks/company-merges/${taskId}`, { method: 'GET', headers: { 'Authorization': `Bearer ${token}` } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return await response.json(); } ``` -------------------------------- ### User Guides - List and Saved View Metadata Source: https://developer.affinity.co/docs/v2/index Guide on retrieving metadata for Lists or Saved Views. ```APIDOC ## User Guides - List and Saved View Metadata ### Description Retrieve metadata on Lists or Saved Views. ### Endpoints - GET `/v2/lists` - GET `/v2/lists/{listId}/saved-views` ### Parameters #### Path Parameters - **listId** (string) - Required - The ID of the list. ``` -------------------------------- ### Retrieve Opportunities with Pagination (Python) Source: https://developer.affinity.co/docs/v2/index Fetches a paginated list of opportunities using Python. Requires an Authorization header with a Bearer token. This example uses the 'requests' library. ```python import requests url = "https://api.affinity.co/v2/opportunities?cursor=ICAgICAgYmVmb3JlOjo6Nw&limit=100&ids=1" headers = { 'Authorization': 'Bearer ' } response = requests.get(url, headers=headers) print(response.json()) ``` -------------------------------- ### Get Company Lists Request Example (Ruby) Source: https://developer.affinity.co/docs/v2/index This Ruby snippet shows how to retrieve lists associated with a company using the 'httparty' gem. It sends a GET request to the API endpoint, providing the company ID and the authorization token in the headers. ```ruby require 'httparty' company_id = '{companyId}' token = '' response = HTTParty.get("https://api.affinity.co/v2/companies/#{company_id}/lists?cursor=ICAgICAgYmVmb3JlOjo6Nw&limit=100", headers: { 'Authorization' => "Bearer #{token}" } ) puts response.body ``` -------------------------------- ### Get Company Lists Request Example (Node.js) Source: https://developer.affinity.co/docs/v2/index This Node.js snippet shows how to fetch lists associated with a specific company. It uses the 'axios' library to make a GET request to the API, including the company ID in the URL and an authorization header. ```javascript const axios = require('axios'); const companyId = '{companyId}'; const token = ''; axios.get(`https://api.affinity.co/v2/companies/${companyId}/lists?cursor=ICAgICAgYmVmb3JlOjo6Nw&limit=100`, { headers: { 'Authorization': `Bearer ${token}` } }) .then(response => { console.log(response.data); }) .catch(error => { console.error(error); }); ``` -------------------------------- ### User Guides - Company/Person List Entries Source: https://developer.affinity.co/docs/v2/index Guide on retrieving all rows for a given Company or Person across all Lists. ```APIDOC ## User Guides - Company/Person List Entries ### Description Retrieve all rows for a given Company or Person across all Lists they appear in. ### Endpoints - GET `/v2/companies/{companyId}/list-entries` - GET `/v2/persons/{personId}/list-entries` ### Parameters #### Path Parameters - **companyId** (string) - Required - The ID of the company. - **personId** (string) - Required - The ID of the person. ``` -------------------------------- ### Fetch Opportunity Notes using Python Source: https://developer.affinity.co/docs/v2/index This Python script demonstrates how to retrieve notes for an opportunity using the 'requests' library. It constructs the API endpoint URL, sets the necessary headers including the authorization token, and makes a GET request. ```python import requests def get_opportunity_notes(opportunity_id, auth_token): url = f"https://api.affinity.co/v2/opportunities/{opportunity_id}/notes" headers = { "Authorization": f"Bearer {auth_token}", "Content-Type": "application/json" } params = { "limit": 20, "totalCount": False } try: response = requests.get(url, headers=headers, params=params) response.raise_for_status() # Raise an exception for bad status codes return response.json() except requests.exceptions.RequestException as e: print(f"Error fetching opportunity notes: {e}") return None # Example usage: # opportunity_id = 'YOUR_OPPORTUNITY_ID' # auth_token = 'YOUR_TOKEN_HERE' # notes_data = get_opportunity_notes(opportunity_id, auth_token) # if notes_data: # print(notes_data) ``` -------------------------------- ### Example AI Notetaker Note Response (JSON) Source: https://developer.affinity.co/docs/v2/index This is an example JSON response for an AI Notetaker note. It includes details such as the note's ID, type, content (HTML), creator information, mentions, and timestamps for creation and update. ```json { "id": 1, "type": "ai-notetaker", "content": { "html": "

This is an AI Notetaker note!

" }, "creator": { "id": 1, "firstName": "Jane", "lastName": "Doe", "primaryEmailAddress": "jane.doe@acme.co", "type": "internal" }, "mentions": [ ], "createdAt": "2023-01-01T00:00:00Z", "updatedAt": "2023-01-21T00:00:00Z" } ``` -------------------------------- ### Get Meetings with Curl Source: https://developer.affinity.co/docs/v2/index Example of how to retrieve a list of meetings using the curl command. This includes parameters for cursor, limit, and filtering, along with authorization headers. ```shell curl -i -X GET \ 'https://api.affinity.co/v2/meetings?cursor=ICAgICAgYmVmb3JlOjo6Nw&limit=100&filter=string' \ -H 'Authorization: Bearer ' ``` -------------------------------- ### Get Person Merge Status (Node.js Request) Source: https://developer.affinity.co/docs/v2/index Example Node.js code using `axios` to fetch the status of a person merge. It takes a `mergeId` and includes the Authorization header. ```javascript const axios = require('axios'); const token = 'YOUR_TOKEN_HERE'; const mergeId = 'YOUR_MERGE_ID'; // Replace with the actual mergeId axios.get(`https://api.affinity.co/v2/person-merges/${mergeId}`, { headers: { 'Authorization': `Bearer ${token}` } }) .then(response => { console.log('Person merge details:', response.data); }) .catch(error => { console.error('Error fetching merge details:', error.response ? error.response.data : error.message); }); ``` -------------------------------- ### List Websites Source: https://developer.affinity.co/docs/v2/index Retrieves a list of websites with pagination support. ```APIDOC ## GET /websites/developer_affinity_co_v2 ### Description Retrieves a list of websites with pagination support, allowing clients to fetch data incrementally. ### Method GET ### Endpoint /websites/developer_affinity_co_v2 ### Parameters #### Query Parameters - **cursor** (string) - Optional - Cursor for the next or previous page. Example: `cursor=ICAgICAgYmVmb3JlOjo6Nw` - **limit** (integer) - Optional - Number of items to include in the page. Default: 100. Example: `limit=100` ### Response #### Success Response (200) - **X-Ratelimit-Limit-User** (integer) - Number of requests allowed per minute for the user. - **X-Ratelimit-Limit-User-Remaining** (integer) - Number of requests remaining for the user. - **X-Ratelimit-Limit-User-Reset** (integer) - Time in seconds before the limit resets for the user. - **X-Ratelimit-Limit-Org** (integer) - Number of requests allowed per month for the account. - **X-Ratelimit-Limit-Org-Remaining** (integer) - Number of requests remaining for the account. - **X-Ratelimit-Limit-Org-Reset** (integer) - Time in seconds before the limit resets for the account. #### Response Example (No example provided for the response body in the input text. Headers are described above.) ```