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 :
Microsoft Dynamics CRM (Archived)

Call Web api from Custom workflow

(0) ShareShare
ReportReport
Posted on by

Hi,

I have developed Web api, Custom workflow ( developed in C# ) and created a new Process.

From process I need to call Workflow ( I am done ) and from workflow I need to call web api .

I don't know how to call Web api from workflow.

Please help me.

Thanks in advance..

Kind regards

Martin

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    PranavShroti Profile Picture
    4,510 on at
    RE: Call Web api from Custom workflow

    Hi, you can use something like this in your server side code:

    using (WebClient client = new WebClient())

               {            

                   client.UseDefaultCredentials = true;

                   byte[] responseBytes = client.DownloadData(new Uri("<<your web api url>>/accounts(<<GUID>>)"));

                   string response = Encoding.UTF8.GetString(responseBytes);

                   // parse the json response

               }

  • Community Member Profile Picture
    on at
    RE: Call Web api from Custom workflow

    Hi,

    Thank you for answer,

    I already tried, got the error:

    Unexpected exception from plug-in (Execute): SWGCRMWinterProInterface.SWGCRMWinterProInterface: System.Security.SecurityException: Fehler bei der Anforderung des Berechtigungstyps "System.Security.Permissions.EnvironmentPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".

    Kind regards

    martin

  • PranavShroti Profile Picture
    4,510 on at
    RE: Call Web api from Custom workflow

    Hi,

    Another option you can try is to update a field on form, which will trigger WebApi call "onchange" event.

    Will it be possible to describe exact scenario why do you wana call WebApi from server side code?

  • Community Member Profile Picture
    on at
    RE: Call Web api from Custom workflow

    Hi,

    basically I need to call some web api from workflow, if you know some better way please help me...

    Kind regards

    Martin

  • Suggested answer
    PranavShroti Profile Picture
    4,510 on at
    RE: Call Web api from Custom workflow

    Server side and Client side scripts are different for a reason.

    They are not meant to cross paths, hence there is no simple way of doing this in CRM.

    I would suggest check rewriting whole code either server side (Plugin/WF) or client side (JS/WebAPI).  

  • Community Member Profile Picture
    on at
    RE: Call Web api from Custom workflow

    Hi,

    Can you give me a some idea, how I should change it, please ?

    Currently my code look like:

     protected override void ExecuteInternal(LocalWorkflowContext context)
            {
                // Todo: implement your logic here
                //var emailRef = this.EmailReference.Get(context.CodeActivityContext);
                
                    using (WebClient client = new WebClient())
                    {
                        client.UseDefaultCredentials = true;                   
                        byte[] responseBytes = client.DownloadData(new Uri("https://mywebaiurl"));                    
                        string response = Encoding.UTF8.GetString(responseBytes); 
                    }            
    
                    
            }


    Thanks in advance..

    Kind regards

    Martin

  • Verified answer
    PranavShroti Profile Picture
    4,510 on at
    RE: Call Web api from Custom workflow

    Code will only work for OnPremise environments and not for Online.

    Kindly check below post:

    community.dynamics.com/.../knowhow-can-we-make-web-api-calls-from-plugins-in-dynamics-crm-2016

  • Community Member Profile Picture
    on at
    RE: Call Web api from Custom workflow

    Hi,

    I found the solution:

    protected override void ExecuteInternal(LocalWorkflowContext context)
            {
                // Todo: implement your logic here
                //var emailRef = this.EmailReference.Get(context.CodeActivityContext);
                
                    using (WebClient client = new WebClient())
                    {
                        client.UseDefaultCredentials = true;   ------------------  remove this line                
                        byte[] responseBytes = client.DownloadData(new Uri("https://mywebaiurl"));                    
                        string response = Encoding.UTF8.GetString(responseBytes); 
                    }            
    
                    
            }


    Kind regards

    Martin

  • Community Member Profile Picture
    on at
    RE: Call Web api from Custom workflow

    Testing1

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans