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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Webhook to azure functions timeouts

(0) ShareShare
ReportReport
Posted on by 145

Hi,

I have an Azure function and also a registered webhook in plugin registration tool. I've registered a step on an entity update, whenever I update this entity I get this error: 

  • The webhook call failed because the Http request timed out at client side. Please check your webhook request handler.

I've checked the logs of my azure function, no errors. But I noticed that when the execution time is more that 1 min this exception occurs. So is there a timeout for webhook call ? and how to fix this ?

Thanks

I have the same question (0)
  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 Moderator on at

    Hi Khaled Rimawi,

    Are you passing parameters into a Durable Function? This error can occur if the parameters passed into a Durable Function are not read correctly. It would be good to take a look at your webhook and any associated code.

  • Khaled Rimawi Profile Picture
    145 on at

    Hi Adrian,

    the Azure function I'm using is a v1 (.net framework) http trigger function, webhook passes the execution context to it, I can see that the azure function runs successfully , but this exception appears on the CRM interface for the user , here is how I registered the webhook:

    pastedimage1606205591526v1.png

    and then i registered a step & image : 

    pastedimage1606205704771v2.png

    pastedimage1606206173148v3.png

    this is a snippet of my code:

     [FunctionName("ResolveProgramScoreLevel")]
            public static async Task Run([HttpTrigger(AuthorizationLevel.Admin,  "post", Route = null)]HttpRequestMessage req, TraceWriter log)
            {
                try
                {
                    if(req == null)
                    {
                        log.Error($"{nameof(req)} is null");
                        return new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent($"{nameof(req)} is null") };
                    }
    
                    // Parse request data to json string and retreive relevant data from context
                    string requestJsonContext = req.Content.ReadAsStringAsync().Result;
                    log.Info(requestJsonContext);
                    if (string.IsNullOrEmpty(requestJsonContext))
                    {
                        log.Error($"[{nameof(Run)}] - Invalid request, the recieved context data from the webhook call is null or empty...");
                        return new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("Invalid request, the recieved context data from the webhook call is null or empty...") };
                    }
    
                    //Retrieve webhook context from request to get relevant incident data 
                    RemoteExecutionContext context = DeserializeJsonString(requestJsonContext);// parse request json data to RemoteExecutionContext object 
    
                    #region context validation
                    //context validation
    
                    //check if this function was requested on an update event
                    if (context.MessageName.ToLower() != "update")
                    {
                        log.Error($"[{nameof(Run)}] - Invalid request, this function was not triggered on update message");
                        return new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("Invalid request, this function was not triggered on update event") };
                    }
    
                    //check if context contains the target case
                    if (!context.InputParameters.Contains("Target"))
                    {
                        log.Error($"[{nameof(Run)}] - Invalid request, context doesn't contain the target entity");
                        return new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("Invalid request, context doesn't contain the target entity") };
                    }
    
                    //check if the context contains the image of case
                    if (!context.PostEntityImages.Contains("image"))
                    {
                        log.Error($"[{nameof(Run)}] - Invalid request, context doesn't contain the image entity");
                        return new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("Invalid request, context doesn't contain the image entity") };
                    }
    
                    #endregion
    
                    var targetCase = ((Entity)context.InputParameters["Target"]).ToEntity();
                    var casePostImage = context.PostEntityImages["image"].ToEntity();
    
                    var testScore = casePostImage.Contains("new_testscore") ? Convert.ToDouble(casePostImage.Attributes["new_testscore"]) : (double?)null;
                    var requestReason = casePostImage.Contains("new_loa_request_reason") ? (casePostImage.Attributes["new_request_reason"] as EntityReference).Id : (Guid?)null;
    
                    if (targetCase.new_requestsubstatusid != null &&
                       targetCase.new_requestsubstatusid.Id == //some value &&
                       testScore != null &&
                       casePostImage.SubjectId != null &&
                       casePostImage.SubjectId.Id == //some value){
    						// do some logic
    				   }
    				   
    				   return new HttpResponseMessage { StatusCode = HttpStatusCode.OK };
    			}
    			catch (Exception ex)
                {
                    log.Error($"[{nameof(Run)}] - an error has occured, ex : {ex}");
                    return new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(ex.ToString()) };
                }	
        	}
        	
        	 private static RemoteContextType DeserializeJsonString(string jsonString)
            {
                //create an instance of generic type object
                RemoteContextType obj = Activator.CreateInstance();
                MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(jsonString));
                System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(obj.GetType());
                obj = (RemoteContextType)serializer.ReadObject(ms);
                ms.Close();
    
                return obj;
            }

    these are the invocations of my function , it runs fine:

    pastedimage1606206326952v4.png

  • Khaled Rimawi Profile Picture
    145 on at

    Hi,

    I tried to register the step to run asynchronously and I can see that azure function run duration is much less now , it's almost 6 seconds instead of 60. Any idea why?

  • eric.westpac Profile Picture
    15 on at

    Hi Khaled Rimawi , did you managed to resolved this? I'm having the same issue and my webhook is async. Thanks

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 76

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans