From a0b63c3bf08e7024cfe1cf251acd8b10ee8b2fbd Mon Sep 17 00:00:00 2001 From: IsaacAlves7 Date: Sat, 30 May 2026 22:09:00 -0300 Subject: [PATCH] feature: Netsuite integration with Pipefy - Moving of Sales in Client Cards --- .../integration.js | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 integrations/netsuite-integration-pipefy/integration.js diff --git a/integrations/netsuite-integration-pipefy/integration.js b/integrations/netsuite-integration-pipefy/integration.js new file mode 100644 index 0000000..4f06951 --- /dev/null +++ b/integrations/netsuite-integration-pipefy/integration.js @@ -0,0 +1,75 @@ +const axios = require('axios'); + +// Credenciais e URLs +const netsuiteAuth = { + username: '', + password: '', +}; + +const pipefyAuth = { + token: '', // Insira seu token do Pipefy aqui JWT +}; + +const netsuiteUrl = 'https://api.netsuite.com/rest/record/v1/customer'; +const pipefyUrl = 'https://api.pipefy.com/graphql'; + +// Função para obter dados do NetSuite +async function getNetsuiteData() { + try { + const response = await axios.get(netsuiteUrl, { + auth: { + username: netsuiteAuth.username, + password: netsuiteAuth.password, + }, + }); + + return response.data; + } catch (error) { + console.error('Erro ao obter dados do NetSuite:', error); + throw error; + } +} + +// Função para enviar dados para o Pipefy +async function sendToPipefy(data) { + const query = ` + mutation { + createCard(pipe_id: SEU_PIPE_ID, title: "Novo Cliente", fields_attributes: [{field_id: SEU_CAMPO_ID, field_value: "${data.valor}"}]) { + card { + id + } + } + } + `; + + try { + const response = await axios.post(pipefyUrl, { query }, { + headers: { + Authorization: `Bearer ${pipefyAuth.token}`, // Inclir o Token + }, + }); + + return response.data; + } catch (error) { + console.error('Erro ao enviar dados para o Pipefy:', error); + throw error; + } +} + +// Executa a integração +async function runIntegration() { + try { + // Obtém dados do NetSuite + const netsuiteData = await getNetsuiteData(); + + // Envia dados para o Pipefy + const pipefyResponse = await sendToPipefy(netsuiteData); + + console.log('Integração concluída com sucesso:', pipefyResponse); + } catch (error) { + console.error('Erro na integração:', error); + } +} + +// Executar a integração quando o script é executado +runIntegration(); \ No newline at end of file