# Sub Organizations ## Create a sub-organization. `print_mail.sub_organizations.update(SubOrganizationUpdateParams**kwargs) -> SubOrganizationUpdateResponse` **post** `/print-mail/v1/sub_organizations` When creating a user through the API, the verifiedEmail field will automatically be set to true. However, if public signups are used, the email will need to be verified by the user. ### Parameters - `country_code: str` The country code of the sub-organization. - `email: str` The email of the user to be created alongside the sub-organization. - `name: str` The name of the user to be created alongside the sub-organization. - `organization_name: str` The name of the sub-organization. - `password: str` The password of the user to be created alongside the sub-organization. - `phone_number: Optional[str]` The phone number of the user to be created alongside the sub-organization. ### Returns - `class SubOrganizationUpdateResponse: …` - `sub_organization: SubOrganization` The Sub-Organization object. - `id: str` A unique ID prefixed with `sub_org_`. - `country_code: str` The country code of the sub-organization. - `created_at: datetime` The UTC time at which this resource was created. - `limit: int` The limit of mailings the sub-organization can send before being charged overages for the month. - `name: str` The name of the sub-organization. - `object: Literal["sub_org"]` Always `sub_org`. - `"sub_org"` - `spend: int` The current rolling charge for the sub-organization for the month, in cents. - `updated_at: datetime` The UTC time at which this resource was last update. - `usage: int` The amount of mail the sub-organization has sent out this month. - `user: User` The user object. - `id: str` A unique ID prefixed with `user_`. - `api_keys: List[UserAPIKey]` The user's API keys. Contains live and test mode API keys. - `value: str` The value of the API key. - `active_until: Optional[datetime]` An optional date which the API key is active until. After this date, the API key will no longer be valid. - `email: str` The email of the user. - `name: str` The name of the user. - `organization: str` A unique ID prefixed with `user_`. - `pending_invite: bool` Indicates if the user has a pending invite. - `roles: List[str]` The roles given to the user. Roles can be used to restrict access for users. - `verified_email: bool` Indicates if the user has a verified email or not. - `email_preferences: Optional[EmailPreferences]` A set of preferences for how a user should receive emails. - `order_preview_send_preference: Optional[Literal["do_not_send", "send_live_only", "send_live_and_test"]]` The list of preferences for receiving order preview emails. - `"do_not_send"` - `"send_live_only"` - `"send_live_and_test"` - `last_login_time: Optional[datetime]` The date and time at which the user last logged in. - `phone_number: Optional[str]` The phone number of the user. - `previous_emails: Optional[List[str]]` A list of emails the user has previously had. If a user has changed their email before, this list will be populated with all of the emails they once had. ### Example ```python import os from postgrid import PostGrid client = PostGrid( print_mail_api_key=os.environ.get("POSTGRID_PRINT_MAIL_API_KEY"), # This is the default and can be omitted ) sub_organization = client.print_mail.sub_organizations.update( country_code="CA", email="suborg@postgrid.com", name="Calvin", organization_name="PostGrid", password="very-strong-password", phone_number="9059059059", ) print(sub_organization.sub_organization) ``` #### Response ```json { "user": { "id": "user_abc123def456ghi6789", "pendingInvite": false, "organization": "org_abc123def456ghi6789", "email": "user@postgrid.com", "name": "Calvin", "apiKeys": [ { "value": "live_abcdefg" }, { "value": "test_abcdefg" } ], "verifiedEmail": true, "roles": [ "role_abc123def456ghi6789" ] }, "subOrganization": { "usage": 0, "limit": 500, "spend": 0, "name": "PostGrid", "countryCode": "CA", "id": "sub_org_abc123def456ghi6789", "object": "sub_org", "createdAt": "2020-11-12T23:23:47.974Z", "updatedAt": "2020-11-12T23:23:47.974Z" } } ``` ## List sub-organizations. `print_mail.sub_organizations.list(SubOrganizationListParams**kwargs) -> SyncSkipLimit[SubOrganization]` **get** `/print-mail/v1/sub_organizations` List sub-organizations. ### Parameters - `limit: Optional[int]` - `search: Optional[str]` You can supply any string to help narrow down the list of resources. For example, if you pass `"New York"` (quoted), it will return resources that have that string present somewhere in their response. Alternatively, you can supply a structured search query. See the documentation on `StructuredSearchQuery` for more details. - `skip: Optional[int]` ### Returns - `class SubOrganization: …` The Sub-Organization object. - `id: str` A unique ID prefixed with `sub_org_`. - `country_code: str` The country code of the sub-organization. - `created_at: datetime` The UTC time at which this resource was created. - `limit: int` The limit of mailings the sub-organization can send before being charged overages for the month. - `name: str` The name of the sub-organization. - `object: Literal["sub_org"]` Always `sub_org`. - `"sub_org"` - `spend: int` The current rolling charge for the sub-organization for the month, in cents. - `updated_at: datetime` The UTC time at which this resource was last update. - `usage: int` The amount of mail the sub-organization has sent out this month. ### Example ```python import os from postgrid import PostGrid client = PostGrid( print_mail_api_key=os.environ.get("POSTGRID_PRINT_MAIL_API_KEY"), # This is the default and can be omitted ) page = client.print_mail.sub_organizations.list() page = page.data[0] print(page.id) ``` #### Response ```json { "object": "list", "limit": 10, "skip": 0, "totalCount": 1, "data": [ { "usage": 0, "limit": 500, "spend": 0, "name": "PostGrid", "countryCode": "CA", "id": "sub_org_abc123def456ghi6789", "object": "sub_org", "createdAt": "2020-11-12T23:23:47.974Z", "updatedAt": "2020-11-12T23:23:47.974Z" } ] } ``` ## Get a sub-organization. `print_mail.sub_organizations.retrieve(strid) -> SubOrganization` **get** `/print-mail/v1/sub_organizations/{id}` Get a sub-organization. ### Parameters - `id: str` ### Returns - `class SubOrganization: …` The Sub-Organization object. - `id: str` A unique ID prefixed with `sub_org_`. - `country_code: str` The country code of the sub-organization. - `created_at: datetime` The UTC time at which this resource was created. - `limit: int` The limit of mailings the sub-organization can send before being charged overages for the month. - `name: str` The name of the sub-organization. - `object: Literal["sub_org"]` Always `sub_org`. - `"sub_org"` - `spend: int` The current rolling charge for the sub-organization for the month, in cents. - `updated_at: datetime` The UTC time at which this resource was last update. - `usage: int` The amount of mail the sub-organization has sent out this month. ### Example ```python import os from postgrid import PostGrid client = PostGrid( print_mail_api_key=os.environ.get("POSTGRID_PRINT_MAIL_API_KEY"), # This is the default and can be omitted ) sub_organization = client.print_mail.sub_organizations.retrieve( "id", ) print(sub_organization.id) ``` #### Response ```json { "usage": 0, "limit": 500, "spend": 0, "name": "PostGrid", "countryCode": "CA", "id": "sub_org_abc123def456ghi6789", "object": "sub_org", "createdAt": "2020-11-12T23:23:47.974Z", "updatedAt": "2020-11-12T23:23:47.974Z" } ``` ## List users for a sub-organization. `print_mail.sub_organizations.retrieve_users(strid, SubOrganizationRetrieveUsersParams**kwargs) -> SubOrganizationRetrieveUsersResponse` **get** `/print-mail/v1/sub_organizations/{id}/users` List users for a sub-organization. ### Parameters - `id: str` - `limit: Optional[int]` - `search: Optional[str]` You can supply any string to help narrow down the list of resources. For example, if you pass `"New York"` (quoted), it will return resources that have that string present somewhere in their response. Alternatively, you can supply a structured search query. See the documentation on `StructuredSearchQuery` for more details. - `skip: Optional[int]` ### Returns - `List[SubOrganizationRetrieveUsersResponseItem]` - `id: str` A unique ID prefixed with `user_`. - `email: str` The email of the user. - `name: str` The name of the user. - `organization: str` A unique ID prefixed with `user_`. - `pending_invite: bool` Indicates if the user has a pending invite. - `roles: List[str]` The roles given to the user. Roles can be used to restrict access for users. - `verified_email: bool` Indicates if the user has a verified email or not. - `email_preferences: Optional[EmailPreferences]` A set of preferences for how a user should receive emails. - `order_preview_send_preference: Optional[Literal["do_not_send", "send_live_only", "send_live_and_test"]]` The list of preferences for receiving order preview emails. - `"do_not_send"` - `"send_live_only"` - `"send_live_and_test"` - `last_login_time: Optional[datetime]` The date and time at which the user last logged in. - `phone_number: Optional[str]` The phone number of the user. - `previous_emails: Optional[List[str]]` A list of emails the user has previously had. If a user has changed their email before, this list will be populated with all of the emails they once had. ### Example ```python import os from postgrid import PostGrid client = PostGrid( print_mail_api_key=os.environ.get("POSTGRID_PRINT_MAIL_API_KEY"), # This is the default and can be omitted ) response = client.print_mail.sub_organizations.retrieve_users( id="id", ) print(response) ``` #### Response ```json [ { "id": "user_abc123def456ghi6789", "pendingInvite": false, "organization": "org_abc123def456ghi6789", "email": "user@postgrid.com", "name": "Calvin", "verifiedEmail": true, "roles": [ "role_abc123def456ghi6789" ] } ] ``` ## Domain Types ### Email Preferences - `class EmailPreferences: …` A set of preferences for how a user should receive emails. - `order_preview_send_preference: Optional[Literal["do_not_send", "send_live_only", "send_live_and_test"]]` The list of preferences for receiving order preview emails. - `"do_not_send"` - `"send_live_only"` - `"send_live_and_test"` ### Sub Organization - `class SubOrganization: …` The Sub-Organization object. - `id: str` A unique ID prefixed with `sub_org_`. - `country_code: str` The country code of the sub-organization. - `created_at: datetime` The UTC time at which this resource was created. - `limit: int` The limit of mailings the sub-organization can send before being charged overages for the month. - `name: str` The name of the sub-organization. - `object: Literal["sub_org"]` Always `sub_org`. - `"sub_org"` - `spend: int` The current rolling charge for the sub-organization for the month, in cents. - `updated_at: datetime` The UTC time at which this resource was last update. - `usage: int` The amount of mail the sub-organization has sent out this month.