Question

Custom authentication for integration app

  • 12 January 2023
  • 4 replies
  • 191 views

Badge +1

I created a integration app with the UI, which I later converted to a CLI project.

The app integrates with a service that doesn’t have a REST API, but it has a node.js client.  Is it just a matter of adding the logic to the authentication.js script that makes the client call?  Perhaps setting sessionConfig.perform.source to a function?


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

4 replies

Userlevel 4
Badge +9

Hi @benjamink9 👋

Documentation on working in the CLI can be found here: https://github.com/zapier/zapier-platform/blob/master/packages/cli/README.md

In order to connect your app to the Zapier Platform (and all 5000+ other apps supported by the Platform), that software will need to have a publicly-accessible API which you can use to build your Zapier Integration. You can find some high-level information about this concept at the link below:
https://platform.zapier.com/docs/zapier-intro 

If your  app has an API, but doesn’t support REST hooks for triggers, you’ll want to use Zapier’s polling mechanism in a trigger. Setting up a trigger in the CLI is described here: https://github.com/zapier/zapier-platform/blob/master/packages/cli/README.md#triggerssearchescreates and there are some example apps you can review here: https://github.com/zapier/zapier-platform/tree/master/example-apps/trigger 

If your app does not have an API, depending on the functionality of your software and the automations that you'd like to create with Zapier, you might be able to achieve your goals using some of the strategies outlined here: https://zapier.com/blog/add-any-app-to-zapier/ 

Hope that this helps clarify the options you have for your app!

Badge +1

The vendor has an https://en.wikipedia.org/wiki/XML-RPC API.  While I could send the XML messages (I’ve done so with PowerShell), they supply a node.js client to make things easier.  I’d like to be able to use this.

Assuming that this is the contents of the authentication.js:

module.exports = {
type: 'session',
test: {
// function here?
},
fields: [
{
computed: false,
key: 'sender_id',
required: true,
label: 'Sender ID',
type: 'string',
},
{
computed: false,
key: 'sender_password',
required: true,
label: 'Sender Password',
type: 'password',
},
{
computed: false,
key: 'user_id',
required: true,
label: 'User ID',
type: 'string',
},
{
computed: false,
key: 'user_password',
required: true,
label: 'User Password',
type: 'password',
},
{
computed: false,
key: 'company_id',
required: true,
label: 'Company ID',
type: 'string',
},
],
sessionConfig: {
perform: {
// function here?
},
},
};

Can I call a function to perform the authentication and testing?  If so, do you have any examples of doing so?

Badge +1

Based on the session-auth, I can associate a function with the 

module.exports = {
config: {
// "session" auth exchanges user data for a different session token (that may be
// periodically refreshed")
type: 'session',
sessionConfig: { perform: getSessionKey },
...
}

const getSessionKey = async (z, bundle) => {
const response = await z.request({
url: 'https://httpbin.zapier-tooling.com/post',
method: 'POST',
body: {
username: bundle.authData.username,
password: bundle.authData.password,
},
});

// If you're using core v9.x or older, you should call response.throwForStatus()
// or verify response.status === 200 before you continue.
return {
// FIXME: The `|| "secret"` below is just for demo purposes, you should remove it.
sessionKey: response.data.sessionKey || 'secret',
};
};

I could modify the getSessionKey function to interact with the vendor’s client, rather than using the z object.

Does this seem reasonable?

Badge +1

If you are interested, this is the project: https://github.com/craibuc/zapier-intacct.