Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Web api /api/data/v8.2/SendEmailFromTemplate getting "Required field 'RegardingType' is missing" javascript

Posted on by 345

I'm trying to call SendEmailFromTemplate via Web API and am constantly getting "Required field 'RegardingType' is missing".

I've already tried a few variations but I can't seem to find a way to pass this missing field

I'm calling this aciton as :

/api/data/v8.2/SendEmailFromTemplate

{

"TemplateId":"CD512306-14D6-E711-80CE-00155D016797",

"Regarding":  

{

"@odata.type": "Microsoft.Dynamics.CRM.opportunity",

         "@odata.id": "e63d7331-8bcb-e711-80cd-00155d016797"            

},

"Target":

{

"@odata.type": "Microsoft.Dynamics.CRM.email",

          "@odata.id": "d34e3955-59d6-e711-80ce-00155d016797"  

   }

}

but getting the error below:

{"error": {

  "code": "",

  "message": "Required field 'RegardingType' is missing",

  "innererror":    {

     "message": "Required field 'RegardingType' is missing",

     "type": "System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]",

     "stacktrace": "   at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, ExecutionContext executionContext)\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.PostUnboundAction(String operationName, ODataUntypedActionParameters parameters)\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()"

  }

}}

can't seem to be able to understand how to send RegardingType field

I tried the variations bellow but all return the same message:


{
"TemplateId":"CD512306-14D6-E711-80CE-00155D016797",
"Regarding": [ { "opportunityid@odata.bind": "/opportunities(e63d7331-8bcb-e711-80cd-00155d016797)" } ],
"Target": [ { "activityid@odata.bind": "/emails(d34e3955-59d6-e711-80ce-00155d016797)" } ],
"RegardingType":"Microsoft.Dynamics.CRM.opportunity"
}

{
"TemplateId":"CD512306-14D6-E711-80CE-00155D016797",
"Regarding":
{
"@odata.type": "Microsoft.Dynamics.CRM.opportunity",
"@odata.id": "e63d7331-8bcb-e711-80cd-00155d016797",
"@odata.RegardingType": "Microsoft.Dynamics.CRM.opportunity"

},
"@odata.RegardingType": "Microsoft.Dynamics.CRM.opportunity",
"Target":
{
"@odata.type": "Microsoft.Dynamics.CRM.email",
"@odata.id": "d34e3955-59d6-e711-80ce-00155d016797",
"@odata.RegardingType": "Microsoft.Dynamics.CRM.opportunity"
}
}

{
"TemplateId":"CD512306-14D6-E711-80CE-00155D016797",
"Regarding":
{
"@odata.type": "Microsoft.Dynamics.CRM.opportunity",
"@odata.id": "e63d7331-8bcb-e711-80cd-00155d016797",
"@odata.RegardingType": "Microsoft.Dynamics.CRM.opportunity"

},
"Target":
{
"@odata.type": "Microsoft.Dynamics.CRM.email",
"@odata.id": "d34e3955-59d6-e711-80ce-00155d016797",
"@odata.RegardingType": "Microsoft.Dynamics.CRM.opportunity"
}
}

If I try the below (which seemed to be the most logical solution):

{
"TemplateId":"CD512306-14D6-E711-80CE-00155D016797",
"Regarding":
{
"@odata.type": "Microsoft.Dynamics.CRM.opportunity",
"@odata.id": "e63d7331-8bcb-e711-80cd-00155d016797"

},
"RegardingType": "Microsoft.Dynamics.CRM.opportunity",
"Target":
{
"@odata.type": "Microsoft.Dynamics.CRM.email",
"@odata.id": "d34e3955-59d6-e711-80ce-00155d016797"
}
}

I get a different error message:

HTTP/1.1 400 Bad Request
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; odata.metadata=minimal
Expires: -1
Server: Microsoft-IIS/8.5
REQ_ID: 859409a7-565e-43bf-b406-1408162ff220
OData-Version: 4.0
X-AspNet-Version: 4.0.30319
Persistent-Auth: true
X-Powered-By: ASP.NET
Date: Fri, 01 Dec 2017 07:30:25 GMT
Content-Length: 2098

{
"error":{
"code":"","message":"The parameter 'RegardingType' in the request payload is not a valid parameter for the operation 'SendEmailFromTemplate'.","innererror":{
"message":"The parameter 'RegardingType' in the request payload is not a valid parameter for the operation 'SendEmailFromTemplate'.","type":"Microsoft.Crm.CrmHttpException","stacktrace":" at Microsoft.Crm.Extensibility.OData.CrmODataUtilities.ValidateInputParameters(ModelStateDictionary controllerModelState)\r\n at Microsoft.Crm.Extensibility.OData.ActionController.PostUnboundAction(String operationName, ODataUntypedActionParameters parameters)\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()"
}
}
}

Does anyone know how to make this call work?

*This post is locked for comments

  • Verified answer
    Jlavos Profile Picture
    Jlavos 345 on at
    RE: Web api /api/data/v8.2/SendEmailFromTemplate getting "Required field 'RegardingType' is missing" javascript

    Hi, thank you for the suggestion,  I ended up using the solution referred in https://community.dynamics.com/crm/f/117/p/258887/731938#731938

    2072.SendEmailFromTemplateWorking.png

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Web api /api/data/v8.2/SendEmailFromTemplate getting "Required field 'RegardingType' is missing" javascript

    Not sure if this will help, but I just ran that action through Jason Lattimer's CRM REST builder, and this was the jQuery code it came out with.  Maybe you can reverse engineer the call from here?

    var parameters = {};
    parameters.TemplateId = "<template Guid goes here>";
    var regarding = {};
    regarding.primarykeyid = "00000000-0000-0000-0000-000000000000";
    regarding["@odata.type"] = "Microsoft.Dynamics.CRM.entitylogicalname";
    parameters.Regarding = regarding;
    var target = {};
    target.primarykeyid = "00000000-0000-0000-0000-000000000000";
    target["@odata.type"] = "Microsoft.Dynamics.CRM.entitylogicalname";
    parameters.Target = target;
    
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: Xrm.Page.context.getClientUrl() + "/api/data/v8.2/SendEmailFromTemplate",
        data: JSON.stringify(parameters),
        beforeSend: function(XMLHttpRequest) {
            XMLHttpRequest.setRequestHeader("OData-MaxVersion", "4.0");
            XMLHttpRequest.setRequestHeader("OData-Version", "4.0");
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
        },
        async: true,
        success: function(data, textStatus, xhr) {
            var results = data;
        },
        error: function(xhr, textStatus, errorThrown) {
            Xrm.Utility.alertDialog(textStatus + " " + errorThrown);
        }
    });

    Disclaimer:  I didn't test it with actual GUID's, so i can't confirm if it works or not. :-)

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans