add contact search
This commit is contained in:
parent
efb5ec2901
commit
6348b777e1
@ -7,6 +7,7 @@ const triggerTicket = require('./triggers/ticket');
|
|||||||
const triggerUser = require('./triggers/user');
|
const triggerUser = require('./triggers/user');
|
||||||
|
|
||||||
const searchThirdparty = require('./searches/thirdparty');
|
const searchThirdparty = require('./searches/thirdparty');
|
||||||
|
const searchContact = require('./searches/contact');
|
||||||
|
|
||||||
const createThirdparty = require('./creates/thirdparty');
|
const createThirdparty = require('./creates/thirdparty');
|
||||||
const createContact = require('./creates/contact');
|
const createContact = require('./creates/contact');
|
||||||
@ -73,6 +74,7 @@ const App = {
|
|||||||
// If you want your searches to show up, you better include it here!
|
// If you want your searches to show up, you better include it here!
|
||||||
searches: {
|
searches: {
|
||||||
[searchThirdparty.key]: searchThirdparty,
|
[searchThirdparty.key]: searchThirdparty,
|
||||||
|
[searchContact.key]: searchContact,
|
||||||
},
|
},
|
||||||
|
|
||||||
// If you want your creates to show up, you better include it here!
|
// If you want your creates to show up, you better include it here!
|
||||||
|
|||||||
95
dev/examples/zapier/searches/contact.js
Normal file
95
dev/examples/zapier/searches/contact.js
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
module.exports = {
|
||||||
|
key: 'contact',
|
||||||
|
|
||||||
|
// You'll want to provide some helpful display labels and descriptions
|
||||||
|
// for users. Zapier will put them into the UX.
|
||||||
|
noun: 'Contact',
|
||||||
|
display: {
|
||||||
|
label: 'Find a Contact',
|
||||||
|
description: 'Search for contact.'
|
||||||
|
},
|
||||||
|
|
||||||
|
// `operation` is where we make the call to your API to do the search
|
||||||
|
operation: {
|
||||||
|
// This search only has one search field. Your searches might have just one, or many
|
||||||
|
// search fields.
|
||||||
|
inputFields: [
|
||||||
|
{
|
||||||
|
key: 'lastname',
|
||||||
|
type: 'string',
|
||||||
|
label: 'Lastname',
|
||||||
|
helpText: 'Lastname to limit to the search to (i.e. The company or %company%).'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'email',
|
||||||
|
type: 'string',
|
||||||
|
label: 'Email',
|
||||||
|
helpText: 'Email to limit to the search to.'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
perform: async (z, bundle) => {
|
||||||
|
const url = bundle.authData.url + '/api/index.php/contacts/';
|
||||||
|
|
||||||
|
// Put the search value in a query param. The details of how to build
|
||||||
|
// a search URL will depend on how your API works.
|
||||||
|
let filter = '';
|
||||||
|
if (bundle.inputData.lastname) {
|
||||||
|
filter = "t.lastname like \'%"+bundle.inputData.name+"%\'";
|
||||||
|
}
|
||||||
|
if (bundle.inputData.email) {
|
||||||
|
if (bundle.inputData.lastname) {
|
||||||
|
filter += " and ";
|
||||||
|
}
|
||||||
|
filter += "t.email like \'"+bundle.inputData.email+"\'";
|
||||||
|
}
|
||||||
|
const response = await z.request({
|
||||||
|
url: url,
|
||||||
|
// this parameter avoid throwing errors and let us manage them
|
||||||
|
skipThrowForStatus: true,
|
||||||
|
params: {
|
||||||
|
sqlfilters: filter
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//z.console.log(response);
|
||||||
|
if (response.status != 200) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return response.json;
|
||||||
|
},
|
||||||
|
|
||||||
|
// In cases where Zapier needs to show an example record to the user, but we are unable to get a live example
|
||||||
|
// from the API, Zapier will fallback to this hard-coded sample. It should reflect the data structure of
|
||||||
|
// returned records, and have obviously dummy values that we can show to any user.
|
||||||
|
sample: {
|
||||||
|
id: 1,
|
||||||
|
createdAt: 1472069465,
|
||||||
|
name: 'DOE',
|
||||||
|
firstname: 'John',
|
||||||
|
authorId: 1,
|
||||||
|
directions: '1. Boil Noodles\n2.Serve with sauce',
|
||||||
|
style: 'italian'
|
||||||
|
},
|
||||||
|
|
||||||
|
// If the resource can have fields that are custom on a per-user basis, define a function to fetch the custom
|
||||||
|
// field definitions. The result will be used to augment the sample.
|
||||||
|
// outputFields: () => { return []; }
|
||||||
|
// Alternatively, a static field definition should be provided, to specify labels for the fields
|
||||||
|
outputFields: [
|
||||||
|
{
|
||||||
|
key: 'id',
|
||||||
|
type: "integer",
|
||||||
|
label: 'ID'
|
||||||
|
},
|
||||||
|
{key: 'createdAt', type: "integer", label: 'Created At'},
|
||||||
|
{key: 'name', label: 'Name'},
|
||||||
|
{key: 'firstname', label: 'Firstname'},
|
||||||
|
{key: 'directions', label: 'Directions'},
|
||||||
|
{key: 'authorId', type: "integer", label: 'Author ID'},
|
||||||
|
{
|
||||||
|
key: 'style',
|
||||||
|
label: 'Style'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -33,11 +33,6 @@ module.exports = {
|
|||||||
|
|
||||||
// Put the search value in a query param. The details of how to build
|
// Put the search value in a query param. The details of how to build
|
||||||
// a search URL will depend on how your API works.
|
// a search URL will depend on how your API works.
|
||||||
const options = {
|
|
||||||
params: {
|
|
||||||
sqlfilters: "t.nom like \'%"+bundle.inputData.name+"%\'"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let filter = '';
|
let filter = '';
|
||||||
if (bundle.inputData.name) {
|
if (bundle.inputData.name) {
|
||||||
filter = "t.nom like \'%"+bundle.inputData.name+"%\'";
|
filter = "t.nom like \'%"+bundle.inputData.name+"%\'";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user