You are viewing limited content. For full access, please sign in.

Question

Question

Calling a REST web service API from JavaScript or Using Workflow's HTTP Request

asked on June 5, 2018 Show version history

Hi all,

I am creating a Form that makes a http request on click of a button by calling the function below. You can ignore the id and the string encoded via btoa.

function send(){
    var URL = "https://connectwiseSite/v4_6/apis/3.0/company.companies"+id;
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("DELETE", URL, true);
    xmlhttp.setRequestHeader("Content-Type","application/json");
    xmlhttp.setRequestHeader("Authorization", "Basic" + window.btoa('companyid+integratorlogin:integratorpassword'))
} 

The problem is that the API requires you to supply cookies in the format below but I'm not sure if you can do that using JavaScript because of the cross-origin policy.

So, my question is:

1. Is it possible to accomplish a web call like above from the JS section in Forms?

2. Is it possible to perform this type of http request in Workflow?

3. If so, can somebody kindly walk me through how I would go about configuring the HTTP Web Request activity (i.e. what do you need to write in the "Content Body", how would you set up Authorization/Authentication, etc). 

4. If not, how would you accomplish making this call?

I am completely new to Worfklow's HTTP Web Request activity and my knowledge on HTTP request in general is poor. Any response would be appreciated. Thanks in advance!

1 0

Answer

SELECTED ANSWER
replied on June 5, 2018 Show version history

If cookies are involved, I'd use Workflow.

Since this is a DELETE request, there won't be a request body ("Content Body"). You can append the id of the company to the URI as shown above. It's basically a question mark, followed by the parameter name, then equal sign and the parameter value.

For the headers, you can switch to the Advanced Properties section (gear icon on the top right corner) and configure them as name-value pairs:

The %(Auth Value) will be the base64-encoded string for companyid+integratorlogin:integratorpassword. You can use C# for that. See here.

Cookie might be a bit tricky. Typically, when you have this sort of flow in Workflow, you first do an initial web request (GET or POST) which might be something like a website login. Then, Workflow outputs the cookie from that activity and you can use that in subsequent activities. I don't know how your website works so I can't help you there.

Hope this is enough to get you started!

2 0
replied on June 5, 2018

Hi Ege,

Thank you so much for your help!

This was immensely helpful. Regarding cookies, I don't know if the explanation below gives you too much context but this is what it said in the Developer's guide:

When connecting to the ConnectWise Manage API, it is required to supply a cw-app-id or cookie value. This value is assigned by the ConnectWise Platform team in order to better support integrations. Using the ConnectWise Manage cookie we can see if an integration is sending excessive calls and can identify who we need to reach out to in order to let them know.

In order to add the cookie value to your headers, format it by setting the header to cookie and the value to cw-app-id=[value]

 

0 0
replied on June 5, 2018 Show version history

OK, that's easy then. Just use the 'Cookie' request header and enter whatever value you need.

1 0
replied on June 5, 2018

Perfect, once again thanks for the help. I will start playing around and see what happens!

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.