Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Accounts

Describes the Accounts API handler in Optimizely Configured Commerce.

HTTP Verb – GET

URL – /api/v1/accounts

Description – Query user accounts by search criteria

Base – HandlerBase<GetAccountCollectionParameter, GetAccountCollectionResult>

OrderHandlerDescription
500ValidateContextIf 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.
600GetBillToIf 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.
700GetUserProfileQuerySets result.UserProfileQuery property.
800ApplyFilteringIf 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.
900ApplySortSorts query by parameter.Sort. If it is not specified then sorts by UserName.
1000ApplyPagingIf it is user administration then apply standard paging to query.
1100ExecuteQueryExecutes query by calling .ToList() method and sets result of execution to UserProfileCollection field.
1200CreateGetAccountResultsCreate 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:

OrderHandlerDescription
100ValidatePunchoutIf the current session is a punchout session, returns a forbidden error.
500SetParametersSets 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.
600ValidateContextVerifies that current user can create account. Only user with Administrator role can do this..
700ValidateApproverValidates the approver if it is a user administration.
800ValidateEmailVerifies that email is valid and verify that email is unique if it is required.
900ValidateUserNameVerifies that username is unique and meets the rules.
1000ValidatePasswordVerifies that password is valid.
1100AddAccountCreates UserProfile entity and adds it to database.
1200SetAdditionalValuesIf it is not a user administration then sets additional values (websites, currency, activation status, approver) for created account.
1300AddCustomerCreates BillTo and assigns it to UserProfile.
1400UpdateCartIf it is not a user administration and cart already exists then updates cart with new BillTo.
1500AddSessionIf it is not a user administration then adds new session for created user.
1600CopyCustomPropertiesToEntityCopies custom properties to created UserProfile entity.
1700CreateGetAccountResultCreates GetAccountResult for created UserProfile.

HTTP Verb – GET

URL – /api/v1/accounts/{accountId}

Description – Return a single user account

Base – HandlerBase<GetAccountParameter, GetAccountResult>

Handlers:

OrderHandlerDescription
500ValidateContextIf user is not logged in and parameter Id is not specified then returns error.
600GetAccountRetrieves account for current user or specified parameter Id. If account is not found then returns error.
700GetAvailableApproversIf 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.
800GetAvailableRolesIf 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:

OrderHandlerDescription
100ValidatePunchoutIf the current session is a punchout session, returns a forbidden error.
500ValidateContextIf parameter Email specified and it is not valid then returns error.
600GetAccountIf user tries to retrieve someone else's account and has no rights then returns error. Fills GetAccountResult, GetRolesResult, GetRoleNameResult.
700ValidateEmailIf 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.
800UpdateAccountUpdates 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.
850UpdateSubscriptionIf 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.
900UpdateEmailIf parameter Email is not specified or equals to user email, then bypass handler. If parameter Email is specified then update user email.
1000UpdateIsApprovedIf 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.
1100UpdateApproverIf 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.
1200UpdateRoleIf 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.
1300CopyCustomPropertiesToEntityCopies 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:

OrderHandlerDescription
500ValidateContextVerifies that user want to receive his own ShipTos collection or has the rights to receive someone else's ShipTos collection.
600GetAllShipToQueryCreates AllShipToQuery and applies sorting and paging to him.
700GetAssignedShipToQueryCreates AssignedShipToQuery.
800CreateUserShipToCollectionFills UserShipToCollection by iterating through AllShipToQuery.
900CreateCostCodeCollectionFills 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:

OrderHandlerDescription
500ValidateContextVerifies 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.
600AssignUserToAllShipTosIf the user has no assigned shiptos and there are un-assignements, then first assign the user to all the shiptos.
700ProcessAssignmentsIterates 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.
800CreateShipToCollectionJust copies ShipToCollection from parameter to result.
900CreateCostCodeCollectionFills CostCodeCollection by iterating through active BillTo.CustomerCostCodes.