Results 1 to 4 of 4

Thread: Example API code not working

Threaded View

  1. #1
    Join Date
    Jul 2016
    Posts
    10

    Default Example API code not working

    Hi,

    Trying to understand the API structure and have built a web page with JavaScript to create a new job. Should this work (tags and usernames etc. amended)?

    Thanks for any advice.

    <** !DOCTYPE html **>
    <** html **>
    <** title **>Fiery API<** /title **>
    <** body **>

    <** h1 **>This is a Fiery API test to submit a job<** /h1 **>

    <** script **>
    var loginJson = {
    username: **username**,
    password: **password**,
    accessrights: **apikey**,
    };

    var payload = JSON.stringify(loginJson);

    var options = {
    hostname: **hostname**,
    path: '/live/api/v3/login',
    method: 'POST',
    headers: {
    'Content-Type': 'application/json',
    'Content-Length': payload.length,
    },

    rejectUnauthorized: false,
    };

    var req = https.request(options, function (res) {
    var response = '';

    res.setEncoding('utf8');
    res.on('data', function (chunk) {
    response = response + chunk;
    }).on('end', function () {
    // do something with the response here

    // cookie is needed for other api requests
    var cookie = res.headers['set-cookie'];
    });
    });

    req.write(payload);
    req.end();

    fullPath = 'C:\SmartFolders\BlankPDFs\Blank-UK.pdf' # e.g. d:\business_card.pdf
    fs.stat(fullPath, function(err, stats) {
    restler.post('https://' + hostname + '/live/api/v3/jobs', {
    multipart: true,
    headers: {
    cookie: cookie,
    },

    rejectUnauthorized: false,

    data: {
    file: restler.file(fullPath, null, stats.size, null, 'application/octet-stream'),

    // override default number of copies to 1 copies
    'attributes[num copies]': 1,
    },
    }).on('complete', function(response) {
    // do something with the response here

    });
    });
    <** /script **>
    <** /body **>
    <** /html **>

    Last edited by kfstarkey; 07-11-2016 at 11:37 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts