Properties

searchIterator: ((params: Omit<SearchPersonsRequest, keyof PagedRequest> & Omit<PagedRequest, "page_token">) => AsyncGenerator<Unwrapped<FN, PAYLOAD_KEY>>) = ...

Returns an async iterator that yields all person entries matching the given search terms Each yielded array contains up to the number specified in SearchPersonsRequest.page_size of persons. Use this method if you want to process the persons in a streaming fashion.

Please note: the yielded persons array may be empty on the last page.

let page = 0
for await (const entries of affinity.persons.searchIterator({
term: 'Alice',
page_size: 10
})) {
console.log(`Page ${++page} of entries:`, entries)
}

Methods

  • Creates a new person with the supplied parameters.

    Parameters

    Returns Promise<SimplePersonResponse>

    The person resource that was just created.

    const newPerson = await affinity.persons.create({
    first_name: 'Alice',
    last_name: 'Doe',
    emails: ['alice@doe.com'],
    organization_ids: [123456]
    })
    console.log(newPerson)
  • Deletes a person with a specified person_id.

    Parameters

    Returns Promise<boolean>

    true if the deletion was successful

    const success = await affinity.persons.delete({
    person_id: 12345
    })
    console.log(success ? 'Person deleted': 'Person not deleted')
  • Fetches an array of all the global fields that exist on persons.

    Returns Promise<EntityField[]>

    An array of the fields that exist on all persons for your team.

    const personFields = await affinity.persons.getFields()
    console.log(personFields)
  • Searches your teams data and fetches all the persons that meet the search criteria.

    This result is paginated. An initial request returns an object with two fields: persons and PagedResponse.next_page_token. persons contains an array of person resources. The value of PagedResponse.next_page_token should be sent as the query parameter page_token in another request to retrieve the next page of results. While paginating through results, each request must have identical query parameters other than the changing page_token. Otherwise, an Invalid page_token variable error will be returned.

    The absence of a PagedResponse.next_page_token indicates that all the records have been fetched, though its presence does not necessarily indicate that there are more resources to be fetched. The next page may be empty (but then PagedResponse.next_page_token would be null to confirm that there are no more resources). Pass {@link InteractionDatesQueryParams.with_interaction_dates}=true as a query parameter to include dates of the most recent and upcoming interactions with persons. When this parameter is included, persons with no interactions will not be returned in the response. Pass with_interaction_persons=true as a query parameter if with_interaction_dates=true to also get the internal persons associated with the interaction. You can filter by interaction dates by providing additional query parameters like min_last_email_date or max_next_event_date. The value of these query parameters should be ISO 8601 formatted date strings.

    Parameters

    Returns Promise<PagedPersonResponse>

    const { persons: allAlices } = await affinity.persons.search({
    term: 'Alice'
    })
    console.log(allAlices)
  • Updates an existing person with person_id with the supplied parameters.

    Parameters

    Returns Promise<SimplePersonResponse>

    The person resource that was just updated.

    const updatedPerson = await affinity.persons.update({
    person_id: 12345,
    name: 'Acme Corp.',
    person_ids: [38706, 89734]
    })
    console.log(updatedPerson)