Skip to content

🐛 fix: align POST /opportunity body with OpportunityFormDataWithAgentSubmitter#696

Closed
arturasmckwcz wants to merge 2 commits into
developfrom
arturas/opportunity-agent-submitter-contract
Closed

🐛 fix: align POST /opportunity body with OpportunityFormDataWithAgentSubmitter#696
arturasmckwcz wants to merge 2 commits into
developfrom
arturas/opportunity-agent-submitter-contract

Conversation

@arturasmckwcz

Copy link
Copy Markdown
Collaborator

Problem

NewOpportunity (the agent-authenticated "create opportunity" screen) posted to POST /opportunity/ with a body that didn't match the SDK contract OpportunityFormDataWithAgentSubmitter:

  • The agent was sent as agentId (camelCase). The endpoint expects agent_id (snake_case), confirmed against both the SDK type (bumped to need4deed-sdk@0.0.110) and the runtime swagger. Since the schema is additionalProperties: true, the backend silently dropped the unknown key — so opportunities were never linked to their agent.
  • The body also included a contact object that isn't part of the create contract, so the agent's contact details were silently dropped too.

Fix

  • Rename agentIdagent_id so the agent link actually binds.
  • Keep the create body to contract fields only (title, agent_id).
  • Persist contact via a follow-up PATCH /opportunity/:id (ApiOpportunityPatch.contact), chained inside a single mutationFn so there's one toast and one navigation.
  • The contact PATCH is best-effort: if it fails, the create still succeeds and the agent lands on the opportunity profile where contact is editable.
  • Bump need4deed-sdk to 0.0.110.

Testing

  • yarn typecheck
  • yarn lint ✅ (only pre-existing warnings in unrelated files)

🤖 Generated with Claude Code

arturasmckwcz and others added 2 commits June 17, 2026 13:30
…Submitter

NewOpportunity sent `agentId` (camelCase), which the backend ignored, so the
opportunity was never linked to the agent. Rename to `agent_id` per the SDK
contract. The create endpoint does not accept a contact object, so contact is
now persisted via a follow-up PATCH /opportunity/:id; that PATCH is best-effort
and does not fail the create. Bump need4deed-sdk to 0.0.110.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The submit button was only disabled while the mutation was pending, so an
agent could submit before GET /agent/me resolved (or if it errored), sending
agent_id: undefined and creating an unlinked opportunity. Disable submit until
the agent is loaded, and bail in handleSubmit as defense-in-depth.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@arturasmckwcz

Copy link
Copy Markdown
Collaborator Author

Superseded by #693, which rewrote NewOpportunity.tsx (new profile-layout form) and already bumped need4deed-sdk to 0.0.110. The agent-link fix is still needed on the new code (buildCreatePayload hardcodes agent_id: null) and will be addressed in a fresh PR against the rewritten component.

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