Node.js Library

The Duda Partner API Node.js library provides convenient access to the Duda Partner API from applications writing in server-side Javascript.

Documentation

View the duda-partner-api API docs for Node.js. (coming soon).

Check out video demonstrations that explain how to use the library (coming soon).

Requirements

Node 12 or higher.

Installation

Install the package with:

npm install @dudadev/partner-api --save
# or
yarn add @dudadev/partner-api

Examples

Create a new site and user, and generate an SSO link.

const { Duda } = require('@dudadev/partner-api');

const duda = new Duda({ 
  user: 'my-api-user',
  pass: 'my-api-pass',
  maxNetworkRetries: 2 
});

(async function() {
  try {
    // get a list of all templates, pick the first one in the returned array
    const [ first ] = await duda.templates.list();

    // create a new site using the template_id
    const { site_name } = await duda.sites.create({
      template_id: first.template_id
    });

    // create a new account
    const account_name = `everett+${uuidv4()}@duda.co`;
    await duda.accounts.create({ account_name });

    // grant site access to the new user
    await duda.accounts.permissions.grantSiteAccess({
      site_name, account_name,
      permissions: ['EDIT']
    });

    // generate a new SSO link
    const link = await duda.accounts.authentication.getSSOLink({
      site_name,
      account_name,
      target: 'EDITOR'
    });

    // use the generated SSO link
    console.log(link);
  } catch(err) {
    // handle error
    console.log(err);
  }
})();

Callbacks & Promises

const { v4: uuidv4 } = require('uuid');
const { Duda } = require('@dudadev/partner-api');

const duda = new Duda({ 
  user: 'my-api-user',
  pass: 'my-api-pass',
  maxNetworkRetries: 2 
});

const account_name = `example+${uuidv4()}@duda.co`;

// chainable promises

duda.templates.list()
  .then(([ first ]) => {
    return duda.sites.create({
      template_id: first.template_id
    })
  })
  .then(({ site_name }) => {
    return duda.accounts.create({ account_name })
      .then(() => duda.accounts.permissions.grantSiteAccess({
        site_name, account_name, permissions: ['EDIT']
      }))
      .then(() => duda.accounts.authentication.getSSOLink({
        site_name, account_name, target: 'EDITOR'
      }))
  })
  .then((resp) => console.log(resp.url))
  .catch((err) => console.log(err));

// callbacks

duda.templates.list(function(err, templates) {
  if (err) console.log(err);

  const [ first ] = templates;

  duda.sites.create({ template_id: first.template_id }, function(err, site) {
    if (err) console.log(err);

    const account_name = `example+${uuidv4()}@duda.co`;
    const { site_name } = site;

    duda.accounts.create({ account_name }, function(err) {
      if (err) console.log(err);

      duda.accounts.permissions.grantSiteAccess({
        account_name,
        site_name,
        permissions: ['EDIT']
      }, function(err) {
        if (err) console.log(err);

        duda.accounts.authentication.getSSOLink({
          account_name,
          site_name,
          target: 'EDITOR'
        }, function(err, reply) {
          if (err) throw err;

          console.log(reply.url);
        })
      })
    })
  });
})

Did this page help you?