Jump to content
Ultimaker Community of 3D Printing Experts

POST print_job with nodeJS

Recommended Posts


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.



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: '',
              auth: { user: '45fa38b52ea5a998c085145930356bd6', pass: '63bb0fc18a39ba7c787805e80f0be1211144f4083de634deb57f7e7819a640ec', sendImmediately: false},
              formData: formData},
function(error, response, body){
    if (!error && response.statusCode == 201){
        console.log("Print started.");
        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

Hi everybody ! Any update on this one? i'm facing the same result on nodejs.


Moreover : 

I tried with multiple tools : 

- Insomnia : works as expected -> It's possible to start a print job

- Curl command line : works as expected -> It's possible to start a print job

- Post Man : Cannot make it work ( error code : 400 Bad request :  "message": "No file received")

- Python3 : same as PostMan ( the file seems to be received by the printer as i see message in printer's log : (but seems empty?)


Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[450]: 2019-02-12 10:58:10,096 INFO     printJob        Saving received file UM3_MusicNoteKeyChainXL.gcode",
        "Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[450]: 2019-02-12 10:58:10,118 INFO     printJob        File saved as /tmp/UM3_MusicNoteKeyChainXL.gcode",
        "Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[418]: 2019-02-12 10:58:10,125 INFO     controller      Request to start procedure: PRINT",
        "Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[418]: 2019-02-12 10:58:10,130 ERROR    controller      Exception in procedure start",
        "Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[418]: Traceback (most recent call last):",
        "Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[418]: File \"/usr/share/griffin/griffin/printer/controller.py\", line 455, in startProcedure",
        "Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[418]: if not procedure.setup(parameters):",
        "Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[418]: File \"/usr/share/griffin/griffin/printer/procedures/print/printProcedure.py\", line 102, in setup",
        "Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[418]: self._parse_header_step.getFileHandler().cleanup()",
        "Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[418]: AttributeError: 'NoneType' object has no attribute 'cleanup'",
        "Feb 12 10:58:10 ultimakersystem-ccbdd30046a1 python3[450]: 2019-02-12 10:58:10,137 WARNING  printJob        Print of UM3_MusicNoteKeyChainXL could not be started"


All others API ( led, blink, message... ) are working well with digest auth but this one ( maybe because of the multipart/form-data aspect) is not working consistently for me.


Can anyone provide support on handling Print_job api from a webapp (nodejs / python? ) / or a working code?



Share this post

Link to post
Share on other sites


I moved to python3 and here is my working code:

    def StartPrint(parent, file):
        logger.info("Start print job. File: ")
        if os.path.exists(file):
            jobname = os.path.basename(file)
            filepath = file
            # Start a print 
            r = requests.post('', auth=requests.auth.HTTPDigestAuth('45fa38b52ea5a998c085145930356bd6', '63bb0fc18a39ba7c787805e80f0be1211144f4083de634deb57f7e7819a640ec'), files={"file": (jobname, open(filepath, "rb"))} )
            if r.status_code == 201:
                return True
                return False
          logger.info("File doesn't exist!")
          return False

You have to change the IP and auth data to your device.

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

    • Ultimaker Cura | a new interface
      We're not only trying to always make Ultimaker Cura better with the usual new features and improvements we build, but we're also trying to make it more pleasant to operate. The interface was the focus for the upcoming release, from which we would already like to present you the first glance. 
        • Like
      • 130 replies
    • "Back To The Future" using Generative Design & Investment Casting
      Designing for light-weight parts is becoming more important, and I’m a firm believer in the need to produce lighter weight, less over-engineered parts for the future. This is for sustainability reasons because we need to be using less raw materials and, in things like transportation, it impacts the energy usage of the product during it’s service life.
        • Like
      • 12 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!