web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

How to add account/contact/lead as marketing list member using javascript web api?

(0) ShareShare
ReportReport
Posted on by 96

I want to add account/contact/lead as marketing list member using javascript web api.

How to do it in 9.1?

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: How to add account/contact/lead as marketing list member using javascript web api?

    Hello,

    You will have to refactor code (use execution context and use 9.1 webapi instead of 8.2) from my post a bit but generally speaking it should work fine - butenko.pro/.../

  • Suggested answer
    Miguel Lourenco Profile Picture
    on at
    RE: How to add account/contact/lead as marketing list member using javascript web api?

    Hi,

    You can download https://github.com/jlattimer/CRMRESTBuilder I believe it would help you.

    However, answering your question:

    var parameters = {};
    var list = {};
    list.listid = "00000000-0000-0000-0000-000000000000"; 
    list["@odata.type"] = "Microsoft.Dynamics.CRM.list";
    parameters.List = list;
    var members1 = {};
    members1.accountid = "00000000-0000-0000-0000-000000000000"; 
    members1["@odata.type"] = "Microsoft.Dynamics.CRM.account";
    //or
    //members1["@odata.type"] = "Microsoft.Dynamics.CRM.lead";
    //or
    //members1["@odata.type"] = "Microsoft.Dynamics.CRM.contact";
    
    parameters.Members = [members1];
    
    var addListMembersListRequest = {
        List: parameters.List,
        Members: parameters.Members,
    
        getMetadata: function() {
            return {
                boundParameter: null,
                parameterTypes: {
                    "List": {
                        "typeName": "mscrm.list",
                        "structuralProperty": 5
                    },
                    "Members": {
                        "typeName": "Collection(mscrm.crmbaseentity)",
                        "structuralProperty": 4
                    }
                },
                operationType: 0,
                operationName: "AddListMembersList"
            };
        }
    };
    
    Xrm.WebApi.online.execute(addListMembersListRequest).then(
        function success(result) {
            if (result.ok) {
               
            }
        },
        function(error) {
         
        }
    );

    hope it helps

  • S. Hossain Profile Picture
    96 on at
    RE: How to add account/contact/lead as marketing list member using javascript web api?

    I am getting this error while trying to implement action as like you mentioned through crm rest builder:

    This action is not available for a dynamic marketing list.","type":"Microsoft.Dynamics.Solution.Common.CrmException","stacktrace":"   at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, InvocationContext invocationContext, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, ExecutionContext executionContext, Dictionary`2 optionalParameters)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataExecutionContext.Execute(OrganizationRequest request, ExecutionContext executionContext)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.ExecuteOperation(CrmODataExecutionContext context, EdmOperation edmOperation, Dictionary`2 parameters, Dictionary`2 boundParameters)\r\n   at Microsoft.Crm.Extensibility.OData.ActionController.ProcessOperationRequest(String operationName, Dictionary`2 operationParameters, EntityReference entityReference, String boundEntityName, String boundEntityType)\r\n   at Microsoft.Crm.Extensibility.OData.ActionController.<>c__DisplayClass9_0.<PostUnboundAction>b__0()\r\n   at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute[TResult](ILogger logger, EventId eventId, ActivityType activityType, Func`1 func, IEnumerable`1 additionalCustomProperties)\r\n   at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute[TResult](ILogger logger, XrmTelemetryActivityType activityType, Func`1 func)\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"}}}

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: How to add account/contact/lead as marketing list member using javascript web api?

    Hello,

    That's mainly because members of dynamics lists are calculated based on Query you configure for the list. This AddMember message is valid for static lists only.

  • S. Hossain Profile Picture
    96 on at
    RE: How to add account/contact/lead as marketing list member using javascript web api?

    How to add static list then? And it seems that if I add thousands of records using Query it doesn't show on member list tab and sometimes getting error though if I browse the list api items exist there. What could be the reason?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 120 Super User 2025 Season 2

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 119

#3
Erin Lubben Profile Picture

Erin Lubben 66

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans