https://github.com/techmedaddy/zeotap-salesforce-integration
Simulated integration between Zeotap and Salesforce Service Cloud using Node.js. Demonstrates contact sync, API design, and OAuth 2.0 flow understanding.
https://github.com/techmedaddy/zeotap-salesforce-integration
api axios dotenv expressjs jest json nodejs oauth2 render salesforceapi
Last synced: 2 months ago
JSON representation
Simulated integration between Zeotap and Salesforce Service Cloud using Node.js. Demonstrates contact sync, API design, and OAuth 2.0 flow understanding.
- Host: GitHub
- URL: https://github.com/techmedaddy/zeotap-salesforce-integration
- Owner: techmedaddy
- Created: 2025-04-11T08:33:46.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-04-11T11:52:22.000Z (about 1 year ago)
- Last Synced: 2025-04-14T17:14:13.762Z (about 1 year ago)
- Topics: api, axios, dotenv, expressjs, jest, json, nodejs, oauth2, render, salesforceapi
- Language: JavaScript
- Homepage: https://zeotap-salesforce-integration.onrender.com/
- Size: 1.4 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Zeotap β Salesforce Contact Integration (Simulation)
This project simulates an integration between **Zeotap** and **Salesforce Service Cloud**, specifically focusing on the **Contact** object. Built using **Node.js** and **Express**, it demonstrates how to sync customer contact data using Salesforce APIs.
---
## π Use Case and Goals
The purpose of this integration is to **sync customer profile data from Zeotap to Salesforce**, ensuring that contact records in Salesforce are always up-to-date. This helps sales and support teams access the latest customer information.
---
## π§© System Design

## π Data Flow Overview
1. A userβs contact information is updated in Zeotap.
2. Zeotap triggers an API call to our backend service.
3. The backend service authenticates with Salesforce.
4. It then creates or updates the Contact object in Salesforce via its REST API.
---
## π Authentication Method
This integration uses **OAuth 2.0 (Resource Owner Password Credentials Grant)** to authenticate with Salesforce.
### Steps to obtain access token:
1. Make a `POST` request to:
`https://login.salesforce.com/services/oauth2/token`
2. Include the following params in `x-www-form-urlencoded`:
- `grant_type=password`
- `client_id`
- `client_secret`
- `username`
- `password`
3. Salesforce returns an `access_token` and `instance_url`, used in subsequent API calls.
---
## π Key Salesforce Endpoints
| Action | Method | Endpoint |
|----------|--------|----------|
| Create Contact | `POST` | `/services/data/vXX.X/sobjects/Contact/` |
| Update Contact | `PATCH` | `/services/data/vXX.X/sobjects/Contact/{ContactId}` |
| Get Token | `POST` | `https://login.salesforce.com/services/oauth2/token` |
> Replace `vXX.X` with your Salesforce API version (e.g., `v59.0`)
---
## π₯ Sample Requests and Responses
### β
Create Contact - Request (from Zeotap)
```json
{
"FirstName": "Amit",
"LastName": "Sharma",
"Email": "amit.sharma@example.com",
"Phone": "+919999888877"
}
```
### β
Create Contact - Simulated Salesforce Response
```json
{
"id": "0035g00001QWdA2AAL",
"success": true,
"errors": []
}
```
### βοΈ Update Contact - Request
```json
{
"id": "0035g00001QWdA2AAL",
"Phone": "+917777666555",
"MailingCity": "Mumbai"
}
```
### βοΈ Update Contact - Simulated Salesforce Response
```json
{
"status": 204,
"message": "No Content - Contact successfully updated."
}
```
## β οΈ Common Errors, Rate Limits, and Required Fields
### π§ Required Fields
- `LastName` is mandatory when creating a contact.
### β Common API Errors
- `400 Bad Request` β Missing required fields.
- `401 Unauthorized` β Invalid token or expired session.
- `404 Not Found` β Wrong contact ID for update.
### π¦ Rate Limits (per Salesforce documentation)
- 100 API calls per user per 24-hour rolling window (free developer edition).
- Bulk limits apply for large operations.
## π§ͺ Testing (Jest)
Basic unit tests included under `__tests__/salesforceService.test.js` using Jest.
Run with:
```bash
npm test
```

## π Assumptions and Edge Cases
- A contact is assumed to exist in Salesforce if an `id` is provided.
- If no `id` is provided, a new contact is created.
- This simulation assumes perfect data; in a real-world scenario, duplicate detection logic would be needed.
- No retry logic for failed API calls is implemented in this simulation.
## π οΈ Tech Stack
- **Backend**: Node.js, Express
- **HTTP Client**: Axios
- **Environment Config**: dotenv
- **Mock Data**: JSON payloads
- **Deployment**: Render
## βΆοΈ How to Run Locally
### 1. Clone the repo:
```bash
git clone https://github.com/your-username/zeotap-salesforce-integration.git
cd zeotap-salesforce-integration
```
### 2. Install dependencies:
```bash
npm install
```
### 3. Create a `.env` file:
```env
PORT=48753
CLIENT_ID=dummy-client-id
CLIENT_SECRET=dummy-client-secret
USERNAME=dummy-user@example.com
PASSWORD=dummy-password123
SALESFORCE_BASE_URL=https://dummy-instance.salesforce.com
```
### 4. Start the server:
```bash
npm run dev
```
## π« API Endpoint
**POST** `/api/sync-contact`
Handles both contact creation and update depending on presence of `id`.
## π Deployment (Render)
1. Push project to GitHub.
2. Connect repo to [Render.com](https://render.com).
3. Set the following environment variables:
- `PORT`, `CLIENT_ID`, `CLIENT_SECRET`, `USERNAME`, `PASSWORD`, `SALESFORCE_BASE_URL`
4. Build command: `npm install`
Start command: `npm start`
5. Click **βDeploy Web Serviceβ**.
## π Folder Structure
```bash
zeotap-salesforce-integration/
βββ app.js
βββ .env
βββ .gitignore
βββ package.json
βββ README.md
βββ routes/
β βββ contact.js
βββ controllers/
β βββ contactController.js
βββ services/
β βββ salesforceService.js
βββ sample/
β βββ payloads.js
```
---
> π **Note**: This project is a simulation and does not connect to a live Salesforce instance. It is designed to demonstrate API integration structure, flow, and logic for assessment purposes.