Jump to content
Cura Connect | Survey Read more... ×
Ultimaker Community of 3D Printing Experts
korny86

POST print_job with nodeJS

Recommended Posts

Hello,

I try to start a print job over the API of my Ultimaker 3. I read the example in this post

 and tried to port the code from python to nodeJS, but the POST request is just hanging.

 

Code:

var request = require("request");
var fs = require('fs');
  
var formData = {
    "file": {
      value: fs.createReadStream('C:\\Users\\efentzahn\\IKIMUNI_Schornstein_simple2.gcode'),
      options: {
        filename: 'IKIMUNI_Schornstein_simple2.gcode'
      }
    }
};

request.post( {url: 'http://10.53.1.114/api/v1/print_job',
              auth: { user: '45fa38b52ea5a998c085145930356bd6', pass: '63bb0fc18a39ba7c787805e80f0be1211144f4083de634deb57f7e7819a640ec', sendImmediately: false},
              formData: formData},
function(error, response, body){
    if (!error && response.statusCode == 201){
        console.log("Print started.");
    }
    else{
        console.log('Code : ' + response.statusCode)
        console.log('error : ' + error)
        console.log('body : ' + body);
    }
});

 

The auth is working. It must be a problem with the formData. Have anyone tried this with nodeJS until now?

Share this post


Link to post
Share on other sites

It's been a while since I developed anything in Node, but in general the code looks ok.

 

How long have you waited? Maybe you're trying to post a very big file?

 

As a first thing, I would try doing an /api/v1/auth/verify request. Just as a sanity check to test if you are correctly submitting the username and password.

 

If that is working, maybe you can try some of the easier calls that don't need a multipart form, like setting the LED brightness?

 

Otherwise, you may need to check your multipart form code. I know this can be complicated in many languages and it looks like the syntax is ok, but you never know.

(I used Google to find this: https://github.com/request/request#multipartform-data-multipart-form-uploads )

Share this post


Link to post
Share on other sites

The login is working and doing PUT request like pause a print works fine in node.js.

The file is 340kbyte "big". That should be transmitted very fast. After a few seconds (maybe 10?) node ends with the error: "socket hang up".

 

I think the problem is the multipart form part, but i have no clue what it is exactly. I already googled a lot and the code posted above is developed with this example from the request library. But the correct names and needed fields in the multipart form is dependent to the Ultimaker API. So, I have the strong feeling that a Ultimaker developer have to take a look at the code.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Our picks

    • Architect Design Contest | People
      The goal of this contest is to design a set of people figurines that could be used in such a project to make an area, office or mall seem populated. 
      Think of different types of people in different environments, like walking people, people standing still, working people, and both men and women.
       
      • 9 replies
    • Taking Advantage of DfAM
      This is a statement that’s often made about AM/3DP. I'll focus on the way DfAM can take advantage of some of the unique capabilities that AM and 3DP have to offer. I personally think that the use of AM/3DP for light-weighting is one of it’s most exciting possibilities and one that could play a key part in the sustainability of design and manufacturing in the future.
        • Like
      • 3 replies
×

Important Information

Welcome to the Ultimaker Community of 3D printing experts. Visit the following links to read more about our Terms of Use or our Privacy Policy. Thank you!