Skip to content

feat: migrate deals_list and deals_list_all_auto to Pipedrive API v2 - #68

Merged
iamsamuelfraga merged 2 commits into
mainfrom
feat/deals-list-api-v2
Sep 11, 2026
Merged

iamsamuelfraga merged 2 commits into
mainfrom
feat/deals-list-api-v2

Conversation

@iamsamuelfraga

Copy link
Copy Markdown
Collaborator

Motivación

El endpoint v1 /deals está deprecado por Pipedrive y devuelve errores 500 intermitentes al combinar los filtros pipeline_id + status. Esta PR migra deals_list y deals_list_all_auto al endpoint v2 (/api/v2/deals), que es estable y es la vía recomendada por Pipedrive para listados de deals.

Cambios

  • Endpoint /api/v2/deals en lugar de /deals (v1) para deals_list y deals_list_all_auto.
  • Paginación migrada de start/limit a cursor (cursor/limit), acorde al modelo de paginación de v2.
  • Mapeo de filtro user_id → owner_id (nomenclatura v2).
  • owned_by_you resuelto vía /users/me, con cacheado para evitar llamadas repetidas.
  • Normalización de custom_fields compatible tanto con la respuesta de v1 como con la de v2, para no romper consumidores existentes de las tools.

Tests

  • 1039/1039 tests pasando (13 nuevos para cubrir la migración a v2).
  • Lint y build limpios.

Verificación manual

Verificado manualmente contra la API v2 real de Pipedrive: respuestas correctas, sin deprecation_warning en las respuestas (a diferencia del endpoint v1).

Open points

  • package-lock.json ya estaba desincronizado en main antes de esta rama (no introducido por esta PR).
  • El parámetro sort_by en v2 solo admite id, add_time o update_time (v1 admitía más campos); cualquier consumidor que dependa de ordenar por otros campos debe revisarse.
  • Los custom fields de tipo enum/set no se han probado end-to-end contra v2 (solo cubiertos por tests unitarios con mocks).

- Switch deals_list and deals_list_all_auto from the deprecated
  GET /deals (v1) to GET /api/v2/deals, following the existing v2
  pattern already used by stages, deals/convert and installments
- Map the legacy v1 filter surface onto v2 params so callers don't
  need to change: user_id and owned_by_you=1 both resolve to
  owner_id (the latter via a cached GET /users/me lookup); sort
  (field) + sort_by (direction) become sort_by (field) +
  sort_direction; status=all_not_deleted is dropped since v2 has no
  equivalent value
- Replace start/limit offset pagination with v2's cursor pagination:
  deals_list accepts an optional cursor and returns
  additional_data.next_cursor; deals_list_all_auto loops on the
  cursor until it comes back null instead of using the start/limit
  PaginationHelper; start is kept in the schema but deprecated/ignored
  for backward compatibility
- Teach buildResolvedCustomFields to also read custom field values
  nested under a v2-style custom_fields object (v1's flat,
  hash-keyed-at-root layout still takes priority when both are
  present), so custom_fields_resolved keeps working on v2 responses
- Add unit tests for the v2 param mapping, cursor pagination in
  deals_list_all_auto, and nested custom_fields normalization;
  verified manually against the live API (open deals on pipeline 1
  return data with a next_cursor and no deprecation_warning)
…ilters

- Add a hard page cap (MAX_PAGES=1000) and a repeated-cursor guard to
  deals_list_all_auto's pagination loop, throwing a descriptive error
  instead of looping forever when the API returns a non-advancing
  next_cursor (including an empty page that echoes back the same
  cursor it was given)
- Trim the requested limit on the final page to max_items - fetched,
  avoiding an unnecessary over-fetch when max_items isn't a multiple
  of pageSize
- Document in both tools' inputSchema that owned_by_you=1 takes
  precedence over user_id when both are supplied
- Omit sort_direction when no sort field is provided, since
  ListDealsSchema's sort_by (direction) defaults to 'asc' even when
  the caller never passed it — sending a direction without a field
  to sort by is meaningless to the v2 API
- Add tests covering the repeated-cursor guard, the empty-page/same-
  cursor case, the page cap, the trimmed last-page limit, and the new
  sort_direction omission behavior
@iamsamuelfraga
iamsamuelfraga merged commit f0d4100 into main Sep 11, 2026
2 checks passed
@iamsamuelfraga
iamsamuelfraga deleted the feat/deals-list-api-v2 branch September 11, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant