Posting Bigfix Action Via AJAX

Hi Team,

I am trying to post an action using the ajax Query so what i have done till now is i have converted the API call in AJAX Format -

var requestBody = '<?xml version="1.0" encoding="UTF-8"?><BES xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BES.xsd"><SingleAction><Title>Image Move</Title><Relevance>true</Relevance><ActionScript MIMEType="application/x-Fixlet-Windows-Shell">delete "C:\Program Files (x86)\BigFix Enterprise\BES Client\download.jpg" copy "C:\soft\download.jpg" "C:\Program Files (x86)\BigFix Enterprise\BES Client\download.jpg"</ActionScript><SuccessCriteria Option="RunToCompletion"></SuccessCriteria><Target><ComputerName>ptest0056</ComputerName></Target></SingleAction></BES>';
		$.ajax({    
				url: "https://10.1.150.77:52311/api/actions",
                success: function(data) {
				   $("#update_response .update-text").html("You have successfully updated photo<strong>");
					$("#update_response").show();			
                },
				xhrFields: {
                			   withCredentials: true
                			},
                crossDomain: true,
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(textStatus, errorThrown);
                         },
               
                beforeSend: function(xhr) {
                   xhr.setRequestHeader("Authorization", "Basic " + btoa("bigfix_admin" + ":" + "Admin098!"));
                },
				
			    type: 'POST',
                dataType: 'xml',
				contentType:'application/xml',
				cache: false,
				data:requestBody
				
            });

But we are not able to open any action by this method.

However when we are posting it via cURL or IEMCLI it is working perfectly fine.

Example how we are posting it via IEM CLI.

We exported the action and then used
iem login --server=https://10.1.150.77:52311 --user=bigfix_admin --password=Admin098!

and then out Xml file - test.xml

<?xml version="1.0" encoding="UTF-8"?>
<BES xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BES.xsd">
                <SingleAction>
                                <Title>Image Move </Title>
                                <Relevance>true</Relevance>
                                <ActionScript MIMEType="application/x-Fixlet-Windows-Shell">delete "C:\Program Files (x86)\BigFix Enterprise\BES Client\download.jpg"
copy "C:\soft\download.jpg" "C:\Program Files (x86)\BigFix Enterprise\BES Client\download.jpg"</ActionScript>
                                <SuccessCriteria Option="RunToCompletion"></SuccessCriteria>
                                <Target>
                                <ComputerName>ptest0056</ComputerName>
                                </Target>
                </SingleAction>
</BES>

Then posting it using - IEM CLI
iem post “test.xml” actions .

However this is working fine can anyone please help checking why we are not able to post the action using the AJAX call.

Hi Deepakbatra,

It looks like there is a problem with the action script you are trying to post. On the official documentation only these file operations are reported:

delete "<filename>"
move "<source filename>" "<destination filename>"
copy "<source filename>" "<destination filename>"
download <url>

In your case you should submit an xml like the following one:

<?xml version="1.0" encoding="UTF-8"?>
<BES xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BES.xsd">
	<SingleAction>
		<Title>CustomAction</Title>
		<Relevance>true</Relevance>
		<ActionScript>move "C:\Program Files (x86)\BigFix Enterprise\BES Client\download.jpg" "C:\soft\download.jpg" </ActionScript>
	</SingleAction>
</BES>

I have made a double check posting your xml both using IEM CLI and direct call and they have failed with the same “XML Parsing Error”, when I have posted the above xml it has worked fine.

regards
Adolfo

I have edited your post to format for code tags. In the future, for posting code please use the </> formatting icon, or indent code lines by four spaces, or wrap the code in single-backtick characters ` so it will be displayed exactly; otherwise the forum interprets things like xml tags as HTML formatting and does not display them.

1 Like

I’ve added code tags to your post so it displays correctly in the forum - please see my other reply on formatting code / xml so it can be read correctly in forum postings. Thanks!

1 Like

Hi Adolfo,

Sorry the intent of the code was not the action script however the intent was to post action using the AJAX Call, as can have any action script but we wanted to post the action Using AJAX call, however we are getting the error while we are trying posting the action using the AJAX call.

This is the Error-
XMLHttpRequest: Network Error 0x2efd, Could not complete the operation due to error 00002efd.

However we can post action using - NodeJs, IEMCLI, cURL.

Let me brief you what i am trying to achieve.

Created one HTML page and on one button we are trying to call an action and we are running that HTML page on Browser, so once we are opening the action via Button in HTML then we are getting the above-mentioned error.

Here is the Function we are calling.

function update_photo (photo_path) 
	{

		var requestBody = '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<BES xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"BES.xsd\">\r\n                <SingleAction>\r\n                                <Title>Image Move </Title>\r\n                                <Relevance>true</Relevance>\r\n                                <ActionScript MIMEType=\"application/x-Fixlet-Windows-Shell\">delete \"C:\\Program Files (x86)\\BigFix Enterprise\\BES Client\\download.jpg\"\r\ncopy \"C:\\soft\\download.jpg\" \"C:\\Program Files (x86)\\BigFix Enterprise\\BES Client\\download.jpg\"</ActionScript>\r\n                                <SuccessCriteria Option=\"RunToCompletion\"></SuccessCriteria>\r\n                                <Target>\r\n                                <ComputerName>ptest0056</ComputerName>\r\n</Target>\r\n</SingleAction>\r\n</BES>\r\n';
		$.ajax({    
				url: "https://10.1.150.77:52311/api/actions",
                success: function(data) {
				   $("#update_response .update-text").html("You have successfully updated photo<strong>");
					$("#update_response").show();			
                },
				xhrFields: {
                			   withCredentials: true
                			},
                crossDomain: true,
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(textStatus, errorThrown);
                         },
               
                beforeSend: function(xhr) {
                   xhr.setRequestHeader("Authorization", "Basic " + btoa("bigfix_admin" + ":" + "password"));
                },
				
			    type: 'POST',
                dataType: 'xml',
				contentType:'application/xml',
				cache: false,
				data:requestBody
				
            });

Can you please help me how to get rid of this error however I tried googling this error and followed many posts but unfortunately not able to resolve this.

So if anyone has tried posting Action with Specifically AJAX then it can help us resolve the issue