Last active
October 19, 2022 19:07
-
-
Save HenriqueMitsuo/b1e8196782bac1922beb87be77589c89 to your computer and use it in GitHub Desktop.
pipedrive-sandbox-test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pipedrive = require("pipedrive"); | |
const defaultClient = pipedrive.ApiClient.instance; | |
let apiToken = defaultClient.authentications.api_key; | |
apiToken.apiKey = "API KEY"; | |
const dealsApi = new pipedrive.DealsApi(); | |
const dealFieldsApi = new pipedrive.DealFieldsApi(); | |
enum CustomFields { | |
backoffice_name = "2cadc913cdcefcaf06918cb8ff1897134307951f", | |
signed_up_plan = "1ce4d9c12b95c2b85fa78a861f5efd7b0cc5dea3", | |
signed_up_plan_price = "d96136a88a6ae732cfba88090ffca05308f095c7", | |
} | |
const findDeals = async () => { | |
try { | |
const data = await dealsApi.getDeals(); | |
console.log("API called successfully. Returned data: ", data); | |
} catch (error) { | |
console.error("API Returned error: ", error); | |
} | |
}; | |
const findDealsFields = async () => { | |
try { | |
const data = await dealFieldsApi.getDealFields(); | |
console.log("API called successfully. Returned data: ", data); | |
} catch (error) { | |
console.error("API Returned error: ", error); | |
} | |
}; | |
const createDeal = async () => { | |
try { | |
const deal = pipedrive.NewDeal.constructFromObject({ | |
title: "test from api 2", | |
[CustomFields.backoffice_name]: "Teste Provider 2", | |
[CustomFields.signed_up_plan]: "Plano Marketplace 10 cliques", | |
[CustomFields.signed_up_plan_price]: "89,99", | |
}); | |
const data = await dealsApi.addDeal(deal); | |
console.log("API called successfully. Returned data: ", data); | |
} catch (error) { | |
console.error("API Returned error: ", error); | |
} | |
}; | |
const execute = async () => { | |
// await findDeals(); | |
// await findDealsFields(); | |
await createDeal(); | |
}; | |
const main = async () => { | |
console.log("SCRIPT STARTED"); | |
console.time("script total execution time:"); | |
await execute(); | |
console.timeEnd("script total execution time:"); | |
}; | |
main() | |
.then(() => {}) | |
.catch((e) => console.error(e)) | |
.finally(() => { | |
console.log("SCRIPT FINISHED"); | |
process.exit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment