Heray-Was-Here
Server : Apache
System : Linux mail.lomejor.cr 6.8.0-1059-azure #65~22.04.1-Ubuntu SMP Thu May 28 16:59:19 UTC 2026 x86_64
User : www-data ( 33)
PHP Version : 8.2.31
Disable Function : NONE
Directory :  /var/www/erp/dev/examples/zapier/creates/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/erp/dev/examples/zapier/creates/contact.js
/*jshint esversion: 6 */
// create a particular contact by name
const createContact = async (z, bundle) => {
    const apiurl = bundle.authData.url  + '/api/index.php/contacts';

    const response = await z.request({
        method: 'POST',
        url: apiurl,
        body: {
            name: bundle.inputData.name,
            name_alias: bundle.inputData.name_alias,
            ref_ext: bundle.inputData.ref_ext,
            ref_int: bundle.inputData.ref_int,
            address: bundle.inputData.address,
            zip: bundle.inputData.zip,
            town: bundle.inputData.town,
            country_code: bundle.inputData.country_code,
            country_id: bundle.inputData.country_id,
            country: bundle.inputData.country,
            phone: bundle.inputData.phone,
            email: bundle.inputData.email,
            sens: 'fromzapier'
        }
    });
    const result = z.JSON.parse(response.content);
    // api returns an integer when ok, a json when ko
    return result.response || {id: response};
};

module.exports = {
    key: 'contact',
    noun: 'Contact',

    display: {
        label: 'Create Contact',
        description: 'Creates a contact.'
    },

    operation: {
        inputFields: [
            {key: 'name', required: true},
            {key: 'name_alias', required: false},
            {key: 'address', required: false},
            {key: 'zip', required: false},
            {key: 'town', required: false},
            {key: 'email', required: false}
        ],
        perform: createContact,

        sample: {
            id: 1,
            name: 'DUPOND',
            name_alias: 'DUPOND Ltd',
            address: 'Rue des Canaries',
            zip: '34090',
            town: 'MONTPELLIER',
            phone: '0123456789',
            fax: '2345678901',
            email: 'robot@domain.com'
        },

        outputFields: [
            {key: 'id', type: "integer", label: 'ID'},
            {key: 'name', label: 'Name'},
            {key: 'name_alias', label: 'Name alias'},
            {key: 'address', label: 'Address'},
            {key: 'zip', label: 'Zip'},
            {key: 'town', label: 'Town'},
            {key: 'phone', label: 'Phone'},
            {key: 'fax', label: 'Fax'},
            {key: 'email', label: 'Email'}
        ]
    }
};

Hry