Google Cloud Print Node API TICKET not working

136 Views Asked by At

This is my code and I am using npm node-gcp and sadly, the ticket is not working, I tried to make the copies = 3 to see if the printer will print 3 and to see if the ticket is working or not, But it's not working :(

I tried all the resources i can find, php ticket, c# ticket, But all are not working,

I am inside the code of npm node-gcp and I am trying to modify its code and see what will work and not, because the original code is he is not passing any ticket.

 return preq({
    method: "POST",
    uri: "https://www.google.com/cloudprint/submit",
    form: {
      title: "Print job title",
      content:
        "test print",
      ticket: {
        version: "1.0",
        print: {
          copies: {
            copies: 3
          },
          page_orientation: {
            type: 0
          },
          margins: {
            top_microns: 0,
            bottom_microns: 0,
            left_microns: 0,
            right_microns: 0
          }
        }
      },

      contentType: "url", //optional, default = url
      printerid: xxxxxxxxxxxxx,
      tags: ["tag1", "tag2"] //optional, default = [],
    },
    headers: {
      "X-CloudPrint-Proxy": "node-gcp",
      Authorization: "OAuth " + this.options.accessToken
    },
    json: true
  })
    .then(function(result) {
      return result;
    })
    .nodeify(cb);
});

i am expecting a response of number of pages is 3 but all I am getting is 1 piece of paper.

1

There are 1 best solutions below

1
LawAbq On

I just had to deal with this issue and discovered that ticket needs to be sent as a stringified json object.

For form, try this instead:

   form: {
      title: "Print job title",
      content:
        "test print",
      ticket: JSON.stringify({
        version: "1.0",
        print: {
          copies: {
            copies: 3
          },
          page_orientation: {
            type: 0
          },
          margins: {
            top_microns: 0,
            bottom_microns: 0,
            left_microns: 0,
            right_microns: 0
          }
        })
      },