An integration between two web services, Pipedrive and Bling using MongoDBAtlas.
Use the package manager node to install the dependencies.
npm i
Use the start script to start the server.
npm run start
https://PipeLing.iagoalmeida1.repl.co
Use this baseUrl to test the API right now.
There are two models in the application, the Day
model and the Deal
model.
A Deal stores all the information from a PipeDrive deal that is necessary for the creation of an order in Bling.
{
"_id": "61e6e4395d3196581600ee54",
"id": 6,
"value": 900,
"date": "2022-01-18T00:00:00.000Z",
"status": "sent",
"__v": 0
}
A Day aggregates all the deals that were made on that date. All the created Deals creates or updates an existing day in order to register the total value of that date.
{
"_id": "61e6e433a0952c33d59bfe28",
"date": "2022-01-17T00:00:00.000Z",
"__v": 0,
"value": 1076
},
GET /deals
Returns all the Deals that are stored in the database
HTTP/1.1 200 OK
[
{
"_id": "61e6e4395d3196581600ee54",
"id": 6,
"value": 900,
"date": "2022-01-18T00:00:00.000Z",
"status": "sent",
"__v": 0
},
...
]
GET /deal/:id
Returns a unique Deal with that ID if it exists.
HTTP/1.1 200 OK
[
{
"_id": "61e6e4395d3196581600ee54",
"id": 6,
"value": 900,
"date": "2022-01-18T00:00:00.000Z",
"status": "sent",
"__v": 0
}
]
POST /deal
This route accepts two body formats, one for simple insertion and other for the PipeDrive webhook integration.
- Simple body format:
body: { "id": 15, "value": 100, "update_time": "01/18/2022", "person_name": "Iago", "status": "won" }
- PipeDrive webhook body format:
{ ... "current": { ... "id": 15, "value": 100, "update_time": "01/18/2022", "person_name": "Iago", "status": "won" ... } ... }
All the Deals created with this route will generate an order creation request to Bling and will update its status to sent
or not_sent
according to the result.
All the Deals created with this route will create or update an existing day with its value.
Returns the created Deal, with two additional values that defines if the deal was inserted into the database and if the deal was send to Bling
HTTP/1.1 201 OK
{
"deal": {
"_id": "61e9545d7aa0c5f7902d81e2",
"id": 15,
"person_name": "Iago",
"value": 100,
"date": "2022-01-18T00:00:00.000Z",
"status": "sent",
"__v": 0
},
"inserted": true,
"sent": true
}
You can set a PipeDrive event based webhook to make every won Deal be automatically stored in the database and sent to Bling API.
Set the event action
to updated
and the event object
to deal
.
At the endpoint URL
, insert this "Create a deal route".
GET /deals/verify/pipedrive
Get all the won Deals in PipeDrive using its API.
Each deal will be inserted in the database if it is not already inserted.
If the deal was not in the database or has the not_sent
status, an order creation request will be sent to Bling.
Returns the results of the routine and all the Deals that were received from Pipedrive.
HTTP/1.1 200 OK
{
"result": {
"read": 7,
"registered": 0,
"sent": 0
},
"data": [
{
"deal": {
"_id": "61e6e4ebdebace6e82488e67",
"id": 1,
"value": 10,
"date": "2022-01-17T00:00:00.000Z",
"status": "sent",
"__v": 0
},
"inserted": false,
"sent": false
},
...
]
}
GET /deals/verify/mongo
Get all the deals from MongoDBAtlas that are not_sent
and attempt to create an order in Bling.
Returns the results of the routine and all the Deals that were found in the MongoDBAtlas.
HTTP/1.1 200 OK
{
"result": {
"read": 7,
"registered": 0,
"sent": 0
},
"data": [
{
"deal": {
"_id": "61e6e4ebdebace6e82488e67",
"id": 1,
"value": 10,
"date": "2022-01-17T00:00:00.000Z",
"status": "sent",
"__v": 0
},
"inserted": false,
"sent": false
},
...
]
}
GET /days
Returns all the Days that are stored in the database
HTTP/1.1 200 OK
[
{
"_id": "61e6e433a0952c33d59bfe28",
"date": "2022-01-17T00:00:00.000Z",
"__v": 0,
"value": 1076
},
...
]
GET /day/:date
Returns a unique Day with that Date if it exists.
HTTP/1.1 200 OK
[
{
"_id": "61e6e433a0952c33d59bfe28",
"date": "2022-01-17T00:00:00.000Z",
"__v": 0,
"value": 1076
},
...
]