famous-memory-11286
10/20/2023, 7:14 PM`
const url = 'https://crm.rdstation.com/api/v1/deals?token=' + env.rdstationApi;
const data = {
campaign: {_id: '63dbef05d54c60000cdb08e7'},
deal: {
deal_stage_id: '64088c1fb4e9e3000c07114b',
name: workflow.nome.first,
rating: 3,
user_id: '63dbef05d54c60000cdb08e1'
},
deal_source: {_id: '64ee63978253cc0018ae26ce'},
contacts: [
{
emails: [{email: workflow.email}],
name: workflow.nome.first,
phones: [{phone: workflow.telefone, type: 'cellphone'}],
title: 'Cliente'
}
],
deal_products: [
{
amount: 1,
base_price: 1000000,
description: workflow.cirurgia,
name: workflow.cirurgia,
price: 1000000
}
]
};
const headers = {
'x-access-token': env.rdstationApi,
};
try {
const response = await axios.post(url, data, { headers });
if (response.status === 200) {
console.log('Enviado ao RD Station com sucesso:', response.status);
workflow.negociacao_id === response.id;
} else {
// Handle other non-successful response statuses here
console.log('Request failed with status:', response.status);
workflow.status === "erro";
}
} catch (error) {
// Handle the error here
console.error('An error occurred during the request:', error.message);
workflow.status === "erro";
}
`