App does not work after installed it for production

We developed an app to communicate pipedrive with freshdesk. The app works properly when running locally and using /?dev=true, but after installing it, does not work… we think that it is due to the port used with express in server.js (port 1800). Maybe the port is not open? or is there some port wich we can use?

I can’t see the server side log, I can only see a “failed to get conversation” error

errorSource: “APP”
headers:
proto: Object
response: “Timeout error while processing the request.”
status: 504
proto: Object

1 Like

This my code in server.js

const express = require('express');
    const app = express();
    const pipedrive = require('pipedrive');
    
    const PORT = 1800;
    
    //pipedrive.Configuration = {};
    
    pipedrive.Configuration.apiToken = 'XXXXXXX'; 
    var serverL = app.listen(PORT, () => {
      console.log(`Listening on port ${PORT}`);
    });

    app.get('/', async (req, res) => {
      const user = await pipedrive.UsersController.getCurrentUserData();
      
      res.send(user);
    });
exports = {
  /**
  * To get the stored note.
  *
  * @param {String} email - The conversation_id of the Agent conversation.
  **/
  getNote: function (payload) {
    
  
    
    
    Usuarioctrl = pipedrive.UsersController;
    Searchctrl = pipedrive.SearchResultsController;
    Personctrl = pipedrive.PersonsController;
    Notasctrl = pipedrive.NotesController;
    //console.log("Notas " + Notasctrl);
   

    
    (async () => {
      try {
        const searchPerson = await Personctrl.findPersonsByName({
          term: payload.email,//'mauan110022@gmail.com',
          searchByEmail: 1
        });
    
        if (searchPerson.data && searchPerson.data.length > 0) {
          for (const result of searchPerson.data) {
            
            try {
              console.log(`${result.name} (id: ${result.id})`);
              const searchResults = await Notasctrl.getAllNotes({
                person_id: result.id
              });
          
              if (searchResults.data && searchResults.data.length > 0) {
                //console.log(" data notas:  " + searchResults.data);
                //console.log("Render data" + searchResults.data);
                var myJSON = JSON.stringify(searchResults.data);
                serverL.close();
                renderData(null, myJSON);
                //for (const result of searchResults.data) {
                  //console.log(`${result.title} ${result.content} (id: ${result.id})`);
                //}
              } else {
                console.log('No notes found');
              }
            } catch (error) {
              console.log(error);
              renderData(error);
            }
            break;
          }
        } else {
          console.log('No user found');
        }
      } catch (error) {
        console.log(error);
        //renderData(error);
      }
    })();
  }
}
1 Like

hey @Carlos_Mora,

Welcome to the community :slight_smile:

Unfortunately, you cannot enable and listen on ports in a serverless app as it is backed by AWS lambda. The reason you can enable the port locally is that the local emulation supports it but the live environment doesn’t.

Hope this helps!

Stay Safe :slight_smile:

3 Likes

Thanks Velmurugan!

Do you happen to know if there is a workaround to solve this?

1 Like

Hey Carlos,

I assume you want to use pipedrive sdk functions on certain events, which you can easily use directly in your server.js instead of setting up a server at a certain port.
Can you please explain the use case of your app here so I can further help :slight_smile:

4 Likes

Hey @Carlos_Mora,

I am giving you a boilerplate code to achieve your requirement. Please let me know if you need further assistance.

const pipedrive = require("pipedrive")

exports = {
getPipeDrive: async function (payload) {
	try {
		const user = await pipedrive.UsersController.getCurrentUserData()

		renderData(null, user)
	} catch (error) {
		renderData(error)
	}
},
getNote: async function (payload) {
	try {
		Usuarioctrl = pipedrive.UsersController
		Searchctrl = pipedrive.SearchResultsController
		Personctrl = pipedrive.PersonsController
		Notasctrl = pipedrive.NotesController

		const searchPerson = await Personctrl.findPersonsByName({
			term: payload.email,
			searchByEmail: 1
		})

		if (searchPerson.data && searchPerson.data.length > 0) {
			for (const result of searchPerson.data) {
				console.log(`${result.name} (id: ${result.id})`)

				const searchResults = await Notasctrl.getAllNotes({
					person_id: result.id
				})

				if (searchResults.data && searchResults.data.length > 0) {
					const myJSON = JSON.stringify(searchResults.data)

					renderData(null, myJSON)
				} else {
					console.log("No notes found")
				}
			}
		} else {
			console.log("No user found")
		}
	} catch (error) {
		console.log(error)

		renderData(error)
	}
  }
}

Best,
Arshath

5 Likes

WOW!!! thank you very much!!! I aprecciate it.

Just one question, where do I put the API token?

You’ll need to configure the config/iparams.json to ask the for the token at the time of installation of the app.
Check documentation here.

Once you do that, you can access the same value using the payload that you receive in the getNote server method.
Like so. payload.iparams.token.

4 Likes