Accounts API handler
Query user accounts by search criteria.
HTTP Verb – GET
URL – /api/v1/accounts
Description – Query user accounts by search criteria
Base – HandlerBase<GetAccountCollectionParameter, GetAccountCollectionResult>
Handlers –
Order | Handler | Description |
---|---|---|
500 | GetAccountCollectionHandler | Gets collection of user accounts. If requester is not salesperson and not administrator then handler returns collection only with current user account. If BillToId parameter specified then handler return accounts only for this BillTo. |
550 | GetAccountAdministrationCollectionHandler | Gets account administration collection. Works only when set IsAdministration parameter to true. Retrieves accounts and applies to them filtering and sorting. |
Order | Handler | Description |
---|---|---|
500 | ValidateContext | If user is not logged in then returns error. Sets CanViewUsers if user has salesperson or user has Administrator role. If CanViewUsers is false and user try to get account collection for other user then returns error. |
600 | GetBillTo | If parameter BillToId has value then retrieves customer for this id and sets him to result.BillTo. Else sets current user BillTo to result.BillTo. If user has salesperson and his id is not equal to user's BillTo.PrimarySalespersonId then returns error. |
700 | GetUserProfileQuery | Sets result.UserProfileQuery property. |
800 | ApplyFiltering | If user has salesperson or parameter UserProfileId is not specified then filter query by BillTo. If result.CanViewUsers is false then filter query by UserProfile. Else if parameter UserProfileId is specified filter query by him. If parameter SearchText is specified then add filtering for FirstName, LastName or UserName by that text. |
900 | ApplySort | Sorts query by parameter.Sort. If it's not specified then sorts by UserName. |
1000 | ApplyPaging | If it is user administration then apply standard paging to query. |
1100 | ExecuteQuery | Executes query by calling .ToList() method and sets result of execution to UserProfileCollection field. |
1200 | CreateGetAccountResults | Create GetAccountResult for each UserProfile in UserProfileCollection and add them to GetAccountResults collection. |
HTTP Verb – POST
URL – /api/v1/accounts
Description – Create user account
Base – HandlerBase<AddAccountParameter, AddAccountResult>
Handlers –
Order | Handler | Description |
---|---|---|
500 | AddAccountHandler | Creates user account. If handler requested from MC then handler set IsApproved, Approver and Role and move on to the next handler. Otherwise, handler creates a new BillTo, assign it to the Cart and sign in. |
800 | AddAccountPunchOutHandler | If the current session is a punchout session then handler generates error result. |
Order | Handler | Description |
---|---|---|
100 | ValidatePunchout | If the current session is a punchout session, returns a forbidden error. |
500 | SetParameters | Sets IsUserAdministration to true if user is logged in. If it is guest checkout then generates username, email and password. If account require activation by email then generates password. |
600 | ValidateContext | Verifies that current user can create account. Only user with Administrator role can do this.. |
700 | ValidateApprover | Validates the approver if it is a user administration. |
800 | ValidateEmail | Verifies that email is valid and verify that email is unique if it is required. |
900 | ValidateUserName | Verifies that username is unique and meets the rules. |
1000 | ValidatePassword | Verifies that password is valid. |
1100 | AddAccount | Creates UserProfile entity and adds it to database. |
1200 | SetAdditionalValues | If it is not a user administration then sets additional values (websites, currency, activation status, approver) for created account. |
1300 | AddCustomer | Creates BillTo and assigns it to UserProfile. |
1400 | UpdateCart | If it is not a user administration and cart already exists then updates cart with new BillTo. |
1500 | AddSession | If it is not a user administration then adds new session for created user. |
1600 | CopyCustomPropertiesToEntity | Copies custom properties to created UserProfile entity. |
1700 | CreateGetAccountResult | Creates GetAccountResult for created UserProfile. |
HTTP Verb – GET
URL – /api/v1/accounts/{accountId}
Description – Return a single user account
Base – HandlerBase<GetAccountParameter, GetAccountResult>
Handlers –
Order | Handler | Description |
---|---|---|
500 | GetAccountHandler | Gets account. If requester wants to retrieve not his account and have no rights to see accounts then handler returns error result. If parameter GetAvailableApprovers specified then handler add collection of available approvers to result. If parameter GetAvailableRoles specified then handler add collection of available roles to result. |
Order | Handler | Description |
---|---|---|
500 | ValidateContext | If user is not logged in and parameter Id is not specified then returns error. |
600 | GetAccount | Retrieves account for current user or specified parameter Id. If account is not found then returns error. |
700 | GetAvailableApprovers | If parameter GetAvailableApprovers is not specified then bypass handler. Else populate AvailableApprovers with users which has Administrator or Buyer3 role and has current customer in assigned customers. |
800 | GetAvailableRoles | If parameter GetAvailableRoles is not specified then bypass handler. Else populate AvailableRoles with list of standard roles. |
HTTP Verb – PATCH
URL – /api/v1/accounts/{accountId}
Description – Update a single user account
Base – HandlerBase<UpdateAccountParameter, UpdateAccountResult>
Handlers –
Order | Handler | Description |
---|---|---|
500 | UpdateAccountHandler | Updates account. If requester wants to update not his account and have no rights to update accounts then handler returns error result. If parameter IsApproved specified then account will locked/unlocked (inversely proportional to the value of the parameter) |
800 | UpdateAccountPunchOutHandler | If the current session is a punchout session then handler returns error result. |
Order | Handler | Description |
---|---|---|
100 | ValidatePunchout | If the current session is a punchout session, returns a forbidden error. |
500 | ValidateContext | If parameter Email specified and it is not valid then returns error. |
600 | GetAccount | If user tries to retrieve someone else's account and has no rights then returns error. Fills GetAccountResult, GetRolesResult, GetRoleNameResult. |
700 | ValidateEmail | If parameter Email specified and it is not equal to current user email and system requires unique email and this email already exists then returns error. |
800 | UpdateAccount | Updates user FirstName and LastName. If parameter SetDefaultCustomer is specified then updates default customer. If parameter DefaultCustomerId is specified but customer with this id is not found then returns error. |
850 | UpdateSubscription | If parameter Email is not specified or equals to user email and parameter IsSubscribed is not specified then bypass handler. If parameter Email is specified then subscribe user to to all lists if it needed. If parameter IsSubscribed is specified then subscribe/unsubscribe user to list. |
900 | UpdateEmail | If parameter Email is not specified or equals to user email, then bypass handler. If parameter Email is specified then update user email. |
1000 | UpdateIsApproved | If parameter IsApproved is not specified or not equals to GetAccountResult.IsLockedOut then bypass handler. If current user can't update users then returns error. Fills GetAccountResult.IsLockedOut and GetAccountResult.UserProfile.IsDeactivated with negated IsApproved parameter. |
1100 | UpdateApprover | If user role is not requires approver or approver is not changed then bypass handler. If current user can't update users or parameter Approver is not specified then returns error. Fills ApproverUserProfile with new approver. |
1200 | UpdateRole | If parameter Role is blank or equals to current role then bypass handler. If current user can't update users then returns error. Sets role to user. |
1300 | CopyCustomPropertiesToEntity | Copies custom properties from parameter to GetAccountResult.UserProfile. |
HTTP Verb – GET
URL – /api/v1/accounts/{accountid}/shiptos
Description – Return a collection of ship to customer records associated with a specific user account
Base – HandlerBase<GetAccountShipToCollectionParameter, GetAccountShipToCollectionParameter>
Handlers –
Order | Handler | Description |
---|---|---|
500 | GetAccountShipToCollectionHandler | Gets a collection of ship to customer records and applies filtering and sorting. If requester wants to retrieve shiptos from not his account and have no rights to view accounts then handler returns error result. |
Order | Handler | Description |
---|---|---|
500 | ValidateContext | Verifies that user want to receive his own ShipTos collection or has the rights to receive someone else's ShipTos collection. |
600 | GetAllShipToQuery | Creates AllShipToQuery and applies sorting and paging to him. |
700 | GetAssignedShipToQuery | Creates AssignedShipToQuery. |
800 | CreateUserShipToCollection | Fills UserShipToCollection by iterating through AllShipToQuery. |
900 | CreateCostCodeCollection | Fills CostCodeCollection by iterating through active BillTo.CustomerCostCodes. |
HTTP Verb – PATCH
URL – /api/v1/accounts/{accountid}/shiptos
Description – Update a collection of ship to customer records associated with a specific user account
Base – HandlerBase<UpdateAccountShipToCollectionParameter, UpdateAccountShipToCollectionResult>
Handlers –
Order | Handler | Description |
---|---|---|
500 | UpdateAccountShipToCollectionHandler | Updates user ship to collection. If requester wants to update not his account and have no rights to update accounts then handler returns error result. |
Order | Handler | Description |
---|---|---|
500 | ValidateContext | Verifies that user has the rights to update shiptos collection. Sets HasAssignedShipTos to true if user has assigned shiptos. Sets ProcessAssignments to true if user has assigned shiptos or need to unassign some shiptos. |
600 | AssignUserToAllShipTos | If the user has no assigned shiptos and there are un-assignements, then first assign the user to all the shiptos. |
700 | ProcessAssignments | Iterates through parameter.ShipToCollection and for each shipto does some things: assign/unassign this shipto to user, sets DefaultCostCode for this shipto and if shipto.IsDefaultShipTo is true then updates user's DefaultCustomer field. If after iteration user's DefaultCustomer field still not set then fills him with result.BillTo. |
800 | CreateShipToCollection | Just copies ShipToCollection from parameter to result. |
900 | CreateCostCodeCollection | Fills CostCodeCollection by iterating through active BillTo.CustomerCostCodes. |
Updated over 1 year ago