Skip to content

Feat: add external_id support to create/update operations for Organization#89

Closed
basbz wants to merge 1 commit intoworkos:mainfrom
totalite:feat/external-id-create-update
Closed

Feat: add external_id support to create/update operations for Organization#89
basbz wants to merge 1 commit intoworkos:mainfrom
totalite:feat/external-id-create-update

Conversation

@basbz
Copy link
Contributor

@basbz basbz commented Feb 11, 2026

Add external_id parameter support to create and update operations:

  • WorkOS.Organizations.create_organization/1,2 — accepts :external_id in opts
  • WorkOS.Organizations.update_organization/2,3 — accepts :external_id in opts

This is a follow-up to #83 which added external_id to the structs and added lookup-by-external-id endpoints. With this PR, the SDK fully supports the external_id field across all CRUD operations for Organizations.dd

Add `external_id` parameter support to create and update operations:
- `WorkOS.Organizations.create_organization/1,2` — accepts `:external_id` in opts
- `WorkOS.Organizations.update_organization/2,3` — accepts `:external_id` in opts

This is a follow-up to workos#83 which added `external_id` to the structs and
added lookup-by-external-id endpoints. With this PR, the SDK fully supports
the `external_id` field across all CRUD operations for Organizations.dd
@gjtorikian
Copy link
Contributor

Haven't gotten around to making CI required yet, but could you rewrite the commit message to prepend fix: (same with the PR title)? 🙏

We're switching over to use release-please for automating releases, and conventional commits is a requirement. Thank you!

@greptile-apps
Copy link

greptile-apps bot commented Feb 11, 2026

Greptile Overview

Greptile Summary

This PR extends WorkOS.Organizations.create_organization/1,2 and update_organization/2,3 to accept an :external_id option and include it in the JSON request body, completing Organization CRUD support for external_id.

Tests add coverage for creating and updating organizations with external_id, and the test client mock was updated to echo external_id in its mocked API responses.

Confidence Score: 3/5

  • Mostly safe to merge, but one test mock bug should be fixed to keep coverage meaningful.
  • Core SDK change is straightforward (adds external_id to request bodies), but the Organizations client mock currently builds a response with name: nil due to atom-key access on a string-key decoded JSON body, which can break or weaken test coverage around organization casting.
  • test/support/organizations_client_mock.ex

Important Files Changed

Filename Overview
lib/workos/organizations.ex Adds external_id to create_organization and update_organization request bodies and documents the new option; no functional issues found in this file.
test/support/organizations_client_mock.ex Extends mock responses to include external_id, but introduces a bug where the mocked response name is always nil due to atom-key access on a string-key map.
test/workos/organizations_test.exs Adds test coverage for create/update with external_id; tests look correct but may be impacted by the mock response bug.

Sequence Diagram

sequenceDiagram
    participant App as SDK Consumer
    participant Orgs as WorkOS.Organizations
    participant Client as WorkOS.Client
    participant Http as TeslaClient/HTTP
    participant API as WorkOS API

    App->>Orgs: create_organization(opts incl external_id)
    Orgs->>Client: post("/organizations", body)
    Client->>Http: request(method=POST, url, body)
    Http->>API: POST /organizations {name, domain_data, allow_profiles_outside_organization, external_id}
    API-->>Http: 200 organization JSON (external_id included)
    Http-->>Client: %{status, body}
    Client-->>Orgs: {:ok, Organization.cast(body)}
    Orgs-->>App: {:ok, %Organization{external_id: ...}}

    App->>Orgs: update_organization(org_id, opts incl external_id)
    Orgs->>Client: put("/organizations/{id}", body)
    Client->>Http: request(method=PUT, url, body)
    Http->>API: PUT /organizations/{id} {..., external_id}
    API-->>Http: 200 organization JSON (external_id included)
    Http-->>Client: %{status, body}
    Client-->>Orgs: {:ok, Organization.cast(body)}
    Orgs-->>App: {:ok, %Organization{external_id: ...}}
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link

greptile-apps bot commented Feb 11, 2026

Additional Comments (1)

test/support/organizations_client_mock.ex
Mock response name nil

body = Jason.decode!(request.body) produces a map with string keys (and your assertions below already treat it that way), but the mock success body sets "name" => body[:name], which will always be nil. That can cause the Organization cast to violate its @enforce_keys expectations or hide issues in tests. Use the string key (body["name"]) here (same issue also exists in update_organization/2).

@basbz basbz changed the title Add external_id support to create/update operations for Organization Feat: add external_id support to create/update operations for Organization Feb 11, 2026
@basbz basbz closed this Feb 11, 2026
@basbz
Copy link
Contributor Author

basbz commented Feb 11, 2026

@gjtorikian, sorry didn't notice this before.
Thanks for the link, might be useful for other stuff.
I closed this PR in favour of opening a new one

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants