Skip to content

docs: Document Batch add Contacts to Companies REST API endpoint - #593

Open
promptless-for-oss wants to merge 13 commits into
mautic:7.3from
Promptless:promptless/pr-16512-batch-add-contacts-companies-api
Open

promptless-for-oss wants to merge 13 commits into
mautic:7.3from
Promptless:promptless/pr-16512-batch-add-contacts-companies-api

Conversation

@promptless-for-oss

@promptless-for-oss promptless-for-oss commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Open in Promptless

Adds a "Batch add Contacts to Companies" section to the Companies REST API reference for the new POST /companies/batch/addcontacts endpoint (mautic/mautic PR #16512). Covers the assignments request body, per-pair results, the summary object, per-pair status values, the batch size limit, and change-log behavior. Targets the 7.3 docs branch (source base 7.x).

Latest revision (review feedback from @adiati98)

  • Applied verbatim: the The ``results`` entry properties, The ``summary`` object properties, and Per-pair ``status`` values heading suggestions. The underlines now match the title lengths.
  • Applied with a change: the status row now links to the per-pair status values section instead of saying "below", and has no trailing period, like the other description cells. To make the link work, I added a .. _per-pair status values: label above that section.
  • Applied with a change: the rewritten change-log paragraph is in, including splitting the event-name clause into its own sentence. The facts match the source PR (LOG_TYPE = 'api', the Lead added to the company, prefix, and the API batch assignment and API assignment event names). I formatted the stored action value as a literal, Lead added to the company, {company name}, and used the style guide's curly-brace placeholder. Without that, Vale flagged Lead and company (Mautic.FeatureList) inside the system string, which can't be reworded.

Validation

  • Vale: no findings on any line changed in this PR. The one remaining suggestion is at line 441, which predates this PR.
  • Sphinx build: the new section adds no warnings, and the :ref: to the status values section resolves.

Trigger Events

Add reference for POST /companies/batch/addcontacts (mautic/mautic PR #16512),
covering the assignments request body, per-pair results, summary object,
status values, batch size limit, and change-log behavior.
HTTP request
============

.. vale on

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documented the new POST /companies/batch/addcontacts endpoint and its purpose from this PR. The route is defined in app/bundles/LeadBundle/Config/config.php (mautic_api_companybatchaddcontacts, POST only) and handled by CompanyApiController::batchAddContactsAction, which reads the assignments array from the request body.

Source: mautic/mautic#16512

Comment thread docs/rest_api/companies.rst Outdated
- object
- Overall counts for the batch

Each entry in ``results`` contains the following properties.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The per-pair status/message values and the summary counts (total, succeeded, failed) come from BatchCompanyContactAssignmentModel in this PR (hard-coded message constants; succeeded counts status-200 pairs, failed counts all others). Overall 200 on processed batches, 400/403 request-level errors, and the 500 returned when the batch exceeds api_batch_max_limit (default 200) via the inherited validateBatchPayload() are all verified against the PR's functional tests.

Source: mautic/mautic#16512

@adiati98 adiati98 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@promptless-for-oss please address the suggestions.

Comment thread docs/rest_api/companies.rst Outdated
Comment thread docs/rest_api/companies.rst Outdated
Comment thread docs/rest_api/companies.rst Outdated
@promptless-for-oss

Copy link
Copy Markdown
Contributor Author

Thanks @adiati98! Addressed all three points:

  1. Capitalized 'Integrations' and reworded the 'reports the outcome' verb to 'includes the outcome' to clear the Mautic.FeatureList Vale warnings.
  2. The 'company' warning was on the literal API response message Contact added to company — that's the exact string this endpoint returns (const MESSAGE_ADDED), so rather than change the API's wording I formatted all the per-pair status message values as inline code literals, which is accurate and clears the warning.
  3. Renamed the request-body heading to 'POST parameters' to match the convention used elsewhere on this page and in forms.rst.

Vale now runs clean on all changed lines. (There's one pre-existing Vale suggestion on line 441 about published → 'Active or Available', but it's on the publishedOnly query parameter outside this PR's section, so I left it untouched.)

@adiati98 adiati98 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@promptless-for-oss please address the suggestions.

Comment thread docs/rest_api/companies.rst Outdated
Comment thread docs/rest_api/companies.rst Outdated
@promptless-for-oss

Copy link
Copy Markdown
Contributor Author

Thanks @adiati98! These property tables describe the results array entries and the summary object, which are both sub-groups under the h4 "Properties" section (not nested inside summary itself). I've turned the two intro sentences into proper h5 headings — The results entry properties and The summary object properties — consistent with the h5 subsections already used elsewhere on this page (e.g. "Core fields"/"Professional fields"). Vale is clean on the changed lines.

@adiati98 adiati98 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@promptless-for-oss please address the suggestions.

Comment thread docs/rest_api/companies.rst Outdated
Comment thread docs/rest_api/companies.rst Outdated
Convert the plain-sentence 'Per-pair ``status`` values:' intro into a proper
h5 (~) heading 'Per-pair ``status`` values', a peer of the existing
'The ``results`` entry properties' and 'The ``summary`` object properties'
subsections under the h4 'Properties' section. Addresses @adiati98's review on PR mautic#593.
@promptless-for-oss

Copy link
Copy Markdown
Contributor Author

Thanks @adiati98! Addressed the remaining comment. The plain-sentence Per-pair ``status`` values: intro is now a proper h5 heading — Per-pair status values — a peer of the existing The results entry properties and The summary object properties subsections under the h4 "Properties" section.

To clarify the question in your comment: that table describes the status field of each results entry, not the summary object, so it belongs directly under "Properties" as an h5 rather than nested inside summary. Vale is clean on the changed lines.

@adiati98 adiati98 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@promptless-for-oss please address the suggestions.

Comment thread docs/rest_api/companies.rst Outdated
Comment thread docs/rest_api/companies.rst Outdated
Comment thread docs/rest_api/companies.rst Outdated
Address @adiati98's review on PR mautic#593: trim excess tildes on the
three property-table h5 headings so each underline matches its
heading text length.
@promptless-for-oss

Copy link
Copy Markdown
Contributor Author

@adiati98 Thanks for the review — done. I shortened the three heading underlines to match the reviewer suggestions exactly:

  • The ``results`` entry properties → 30 ~
  • The ``summary`` object properties → 31 ~
  • Per-pair ``status`` values → 22 ~

The changes are pushed to this branch. Vale is clean on the changed lines.

@adiati98 adiati98 modified the milestones: 7.2, 7.3 Sep 9, 2026
@promptless-for-oss
promptless-for-oss marked this pull request as ready for review September 11, 2026 13:49
…-log note

Fix two factual errors surfaced by re-checking merged mautic/mautic PR #16512:
- Over-limit batch requests return HTTP 400, not 500 (validateBatchPayload
  returns HTTP_BAD_REQUEST; testBatchAddContactsExceedsBatchLimit asserts 400).
- The single-add 'Add Contact to Company' endpoint now also writes to the
  Company change log for each new assignment (event name 'API assignment' vs
  the batch endpoint's 'API batch assignment').
Comment thread docs/rest_api/companies.rst Outdated
Comment thread docs/rest_api/companies.rst
@promptless-for-oss

Copy link
Copy Markdown
Contributor Author

I noticed that some CI checks failed for this PR. I'm investigating whether the failures are caused by this suggestion. If they're unrelated or pre-existing, I'll leave this suggestion unchanged and create a separate suggestion if a standalone docs fix is needed.

…tions

Lengthen the three h5 subsection underlines under Properties to match their
title text (including the literal backtick characters RST counts):
'The ``results`` entry properties' (32), 'The ``summary`` object
properties' (33), and 'Per-pair ``status`` values' (26). The prior lengths
were shorter than the titles, which Sphinx flags as malformed section markup.
Verified with rst2html: no 'Title underline too short' warnings remain.
@adiati98

Copy link
Copy Markdown
Member

@promptless-for-oss please rebase to 7.3 branch.

@promptless-for-oss

Copy link
Copy Markdown
Contributor Author

In reply to this discussion

Thanks @adiati98 — on it. I'll rebase this onto the 7.3 branch and update the PR, then follow up here once it's done.

@promptless-for-oss
promptless-for-oss changed the base branch from 7.2 to 7.3 September 16, 2026 07:10
@promptless-for-oss

Copy link
Copy Markdown
Contributor Author

In reply to this discussion

Done, @adiati98 — PR #593 now targets the 7.3 branch. Since 7.3 and 7.2 currently point to the same commit, no rebase was needed and there were no conflicts. The PR still shows its intended single-file change to docs/rest_api/companies.rst and is mergeable pending your review. Let us know if you'd like anything else adjusted.

@adiati98

Copy link
Copy Markdown
Member

@promptless-for-oss please create a PR to cherry-pick the changes here for 8.0 branch.

@promptless-for-oss

Copy link
Copy Markdown
Contributor Author

In reply to this discussion

On it — I'll prepare a PR that cherry-picks these Batch add Contacts to Companies REST API docs onto the 8.0 branch and follow up here with the link.

@promptless-for-oss

Copy link
Copy Markdown
Contributor Author

In reply to this discussion

Done — I've opened a PR that cherry-picks these Batch add Contacts to Companies REST API docs onto the 8.0 branch: #673

It reproduces the approved content from this PR onto 8.0 (one file, +167 lines) and applied cleanly with no conflicts.

@adiati98 adiati98 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@promptless-for-oss please address the suggestions and Vale warnings.

Comment thread docs/rest_api/companies.rst Outdated
Comment on lines +1149 to +1150
The ``results`` entry properties
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The ``results`` entry properties
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The ``results`` entry properties
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied as written in 992d0c8. The heading is now "The results entry properties", and its underline matches the title length. An earlier commit had reverted this underline fix, which is why it still looked unaddressed.

Comment thread docs/rest_api/companies.rst Outdated
Comment on lines +1172 to +1173
The ``summary`` object properties
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The ``summary`` object properties
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The ``summary`` object properties
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied as written in 992d0c8. The heading is now "The summary object properties", and its underline matches the title length.

Comment thread docs/rest_api/companies.rst Outdated
Comment on lines +1192 to +1193
Per-pair ``status`` values
~~~~~~~~~~~~~~~~~~~~~~

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Per-pair ``status`` values
~~~~~~~~~~~~~~~~~~~~~~
Per-pair ``status`` values
~~~~~~~~~~~~~~~~~~~~~~~~~~

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied as written in 992d0c8. The heading is now "Per-pair status values", and its underline matches the title length. I also added a .. _per-pair status values: label above it, so the status row can link to this section.

Comment thread docs/rest_api/companies.rst Outdated
- ``An unexpected error occurred``
- Mautic couldn't process the pair

Mautic records each new assignment made through this endpoint in the Contact's Company change log. It doesn't add a log entry when the Contact already belongs to the Company, and a pair for an existing link still returns a ``200`` status in its result. The 'Add Contact to Company' endpoint also writes to this log for each new assignment. Both endpoints record a ``type`` of ``api`` and an action of 'Lead added to the company, <company name>', and differ only in the event name: this endpoint records 'API batch assignment', while the 'Add Contact to Company' endpoint records 'API assignment'.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Mautic records each new assignment made through this endpoint in the Contact's Company change log. It doesn't add a log entry when the Contact already belongs to the Company, and a pair for an existing link still returns a ``200`` status in its result. The 'Add Contact to Company' endpoint also writes to this log for each new assignment. Both endpoints record a ``type`` of ``api`` and an action of 'Lead added to the company, <company name>', and differ only in the event name: this endpoint records 'API batch assignment', while the 'Add Contact to Company' endpoint records 'API assignment'.
Mautic records each new assignment made through this endpoint in the Contact's Company change log. It doesn't add a log entry when the Contact already belongs to the Company, and a pair for an existing link still returns a ``200`` status in its result. The 'Add Contact to Company' endpoint also writes to this log for each new assignment. Both endpoints record a ``type`` of ``api`` and an action of 'Lead added to the company, <company name>', and differ only in the event name. This endpoint records 'API batch assignment', while the 'Add Contact to Company' endpoint records 'API assignment'.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in 992d0c8, using your wording and sentence split. I checked the facts against the source PR: the api type, the action text, both event names, and the unchanged 200 for an existing link.

I made one small change. The stored action value is now formatted as code: Lead added to the company, {company name}. Vale flagged Lead and company inside that string, but Mautic generates it, so the wording can't change. The placeholder uses curly braces, following the style guide.

Comment thread docs/rest_api/companies.rst Outdated
- ID of the Company in the pair
* - ``status``
- integer
- Per-pair status code. See the status values below.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple of things here:

  • Link the 'status values' because 'below' isn't clear. The 'below' isn't directly the status values.
  • Replace 'below' with 'section', and the period for consistency.
Suggested change
- Per-pair status code. See the status values below.
- Per-pair status code. See the status values section

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 992d0c8, with the link added. The row now reads: Per-pair status code. See the :ref:status values section <per-pair status values>

It links to the "Per-pair status values" section instead of saying "below". There's no trailing period, which matches the other description cells. The link resolves in a local Sphinx build.

@promptless-for-oss

Copy link
Copy Markdown
Contributor Author

In reply to this discussion

Thanks, @adiati98. I'm applying your five inline suggestions and fixing the Vale warnings now, and I'll reply in each thread when the update is on the branch.

…tion

Fix h5 heading underlines, link the per-pair status values section, and
apply the reviewer's change-log paragraph with the action value as a literal
to clear Vale FeatureList findings.
@promptless-for-oss

Copy link
Copy Markdown
Contributor Author

In reply to this discussion

@adiati98 I've applied all five inline suggestions and fixed the Vale warnings in commit 992d0c8. Vale now shows no findings on any line this PR changes. The only remaining suggestion is on line 441, which this PR doesn't touch. I've replied in each thread with the details, including the two suggestions I applied with a small change.

The 8.0 version of this page (PR #673) still has the old 'See the status values below.' wording and change-log sentence. I can make the same edits there if you'd like.

GitHub wouldn't let me re-request your review, so please take another look when you have a moment.

Docs PR: #593

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants