Fusion Manage Forum
Welcome to Autodesk’s Fusion Manage (formerly Fusion 360 Manage) Forum. Share your knowledge, ask questions, and explore popular Fusion Manage topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

XMLHttpRequest in action script

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
sscaife
1309 Views, 7 Replies

XMLHttpRequest in action script

Hi

 

I am having an issue with XMLHttpRequest in an action script.

 

Scenario

 

we run an action script when the workflow state changes, what we want to do is send an email with a ics attachment so that we can add an appointment to a users outlook calendar.

 

As we can't attach a file to an email we have created a simple web api application. To test that PLM can call out to our REST service we pass a name and email address (hard coded) and then the web api forwards these details on in an email.

 

var xhr = new XMLHttpRequest();
var value = '{ "EmailAddress": "joe.bloggs@test.com", "Name": "Joe Bloggs" }';

xhr.open("POST", "http://the-url/api/plm", true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Content-Length', value.length);
xhr.send(value);

 

This actually works however the email and the name are not passed on to my service. My test app works fine.

 

So I changed the request to

 

var xhr = new XMLHttpRequest();
var value = EmailAddress=joe.bloggs@test.com&Name=Joe bloggs;
xhr.open("POST", "http://the-url/api/plm", true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.setRequestHeader('Content-Length', value.length);
xhr.send(value);

 

This throws a SECURITY_ERR on the first line

 

My service is enabled for CORS and my test application works fine sending cross origin requests.

 

Are XMLHttpRequest calls supported in PLM, and if so what am I missing

 

thanks

7 REPLIES 7
Message 2 of 8
jared.sund
in reply to: sscaife

 

sscaife,

 

Great question, and great inovative approach on extending PLM 360's functionality with web servcies!

 

There are acouple of quick changes needed here to get this httpRequest to work.  

 

  1. PLM 360 only supports synchronous  XMLHttpRequests, so you can drop the 'true' argument from your open statement.
  2. Remove xhr.setRequestHeader('Content-Length', value.length);  // not needed here

 

Here's the updated code.

 

var xhr = new XMLHttpRequest();
var value = '{ "EmailAddress": "joe.bloggs@test.com", "Name": "Joe Bloggs" }';

xhr.open("POST", "http://the-url/api/plm");
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(value);

 

Let me know if you have any other issues with this, and how it turns out!

 

 

-Jared

Jared Sund
Sr. Product Line Manager, Product Lifecycle Management
Autodesk, Inc.
Message 3 of 8
tray1
in reply to: jared.sund

Hi Jared,
We are going down this route as we'd like to generate an .ics file to add appointments to peoples diaries via an email. I have requested this in the ideastation but for now we are trying to do it via this route.

 

The code doesn't cause an error in PLM now I've tested it. I just need Steve to test his end

Message 4 of 8
sscaife
in reply to: jared.sund

Sorry for the delay in replying to you, that worked so marked as the answer.

For future reference is it node.js in the backend? seem to recall reading somewhere that node.js is single threaded, and as it appears to run the code on the server and not the browser it makes sense, if this is the case then it will make it easier for us to develop functionality like this going forward, as we can also refer to the node.js documentation.

At least we know to keep all the calls synchronous now 😄

Also thanks for the compliment, much appreciated
Message 5 of 8
alexander.tucker
in reply to: sscaife

Hi,

Attempting to do something similar but needs basic authentication.  Testframework is:

 

var xhr = new XMLHttpRequest();
xhr.open("GET","https://this.particular.service/board/tasks","myusername","mypassword");
xhr.send();


Result is:

There is an error in the script on line 0, column 0. NETWORK_ERR

 

Can't figure out why...  suggestions?

Message 6 of 8

Debug shows failure on the xhr.send();
Message 7 of 8

also whether this GET is in 'GET' or "GET" doesn't make a difference
Message 8 of 8

Hey wait... had this idea... I used a base 64 encoded user+password from another application (Soap UI as my test bench).
Then did a:
xhr.setRequestHeader("Authorization", "Basic YWxleGFuZGVyLnR1Y2tlckBnZW5jby5jb206dXNlcjAx");

Seems to be working...

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report