Rest bpm

I’m trying to get a response from a web site using REST inside a BPM with this code:

var client = new RestClient(uri);
var request = new RestRequest(Method.POST);

string logInParam = “{logIn}”;
request.AddParameter(“application/json”, logInParam, ParameterType.RequestBody);

IRestResponse response = client.Execute(request);

In LINQPad, I get a response, but in the BPM the response is null.

Has anyone used REST inside a BPM and gotten a response? Does anyone have some example code that works in a BPM?

Here’s my generic code, but the detail will vary depending on the way the APIs you’re calling on work:

using (WebClient wclient = new WebClient()
{
    try
    {
        wclient.Headers.Add("Authorization", "Bearer " + token);
        responsefromserver = wclient.DownloadString(endpointUrl + qpath + fquery);
    }
    catch (WebException e)
    {
        WebResponse eResp = e.Response;
        using (Stream respStream = eResp.GetResponseStream())
        {
            StreamReader reader = new StreamReader(respStream);
            string etext = codeident + " Web Error: " + reader.ReadToEnd();
            //this.PublishInfoMessage(etext, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
            //Ice.Diagnostics.Log.WriteEntry(etext);
        }
    }
    catch (Exception e)
    {
        //this.PublishInfoMessage(codeident + " Error: " + e.Message, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
        //Ice.Diagnostics.Log.WriteEntry(codeident + "  Error: " + e.Message);
    }
}
2 Likes

Thanks Daryl. I was able to adapt your code to get my BPM to work.