How to solve statuscode 0 from an xhr.send() in my console dashboard

I have a custom dashboard that allows me to select endpoints for tagging with a client setting.
Users load their credentials into a form input, select computers from a datatable and submit.
An action is submitted with relevance “set of (ids of selected computers) contains computer id” , and the actionscript is ‘setting “whatever” = “xyz” on “{now}” for client’

In my lab, I receive a response text with an action id.
in prod, i receive Failure code: 0

One major difference is that we are using saml login in prod.

Here’s the snippet that fails

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.open("POST", "https://bigfix-url:52311/api/actions");
xhr.setRequestHeader("Content-Type", "application/xml");
xhr.setRequestHeader("Authorization", "Basic " + btoa_creds);
xhr.addEventListener("readystatechange", function() {
	if(this.readyState === 4) {
		if (this.statusCode === 200) { alert(this.responseText); }
		}
	else {alert("Failure code: " + this.statusCode );}
	});
	xhr.send(data);

i’ve had the same results with API authorized nmo account, mo account, local bigfix administrator account.

any advice is appreciated. thanks

Apologies I misread this badly on my earlier response.

I’d try checking the .statusText property to see whether there is a useful error message.

Also consider that wizards.js provides a function ImportXMLToSite() function that should let you avoid setting up a separate session and avoid reauthenticating. You should be able to just build your XML and pass it to this function directly.

edit: spelling on ImportXMLToSite()

Ok I just looked up one of my dashboard sources, and it’s literally as simple as

ImportXMLToSite(strXML,strSite,true)

strXML is the string representation of the XML, strSite is an (optional) Site Name (for an Action it should be an empty string), and ‘true’ or ‘false’ for whether to show the action preview / import preview screen in the Console.

wizards.js should automatically be included in Dashoards, you don’t have to import it explicitly. If you like you can read the source of it in the BES Console\Reference directory.

Thanks Jason,

I will test that today and update with results :slight_smile:

– and Success … this works with SAML/SSO enabled.
Jus a slight modification required on my xml (i had to add the computer ids to the targets, and not depend on relevance for targeting)
The online documentation should be updated to make this more widely known

1 Like

Targeting with Relevance works also (but supplying computer IDs is more efficient up to a point). The structure for that is

<Target>
<CustomRelevance> computer id is contained by set of (123; 456; 789) 
</CustomRelevance>
</Target>