0.4.0 • Published 2 years ago

rs-leads-api v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

rs-leads-api

A small module to post website form submissions to repairshopr's RESTful API Leads module.

Install

  • Available on NPMjs.com
  • yarn add rs-leads-api
  • Add the following variables to your environment: RS_API, RS_URI, and STORES*
RS_API="<Your Repairshopr API Key>"
RS_URI="https://<your_subDomain>.repairshopr.com/api/v1"
STORES="<Stringified JSON object with store data>"
  • import into your project and start generating leads!

Methods

  • getCustomerID(query) * returns the customer ID of the first customer whose name matches query, otherwise returns false
  • recordCustomer(customerData) * Records a new customer in repairshopr with the given customerData
import RS from 'rs-leads-api';
let c = {
	firstname:"John",
	lastname:"Smith",
	email:"Jsmith@email.com",
	phone:"9180000000",
	location:"41st",
	make:"Apple",
	model:"iPhone 13",
	issue:"Screen Repair",
	price:"249.99"
};
RS.recordCustomer(c).then((e,c)=>{
	if(!e) console.log(c)
	else console.log(e)
})
  • getLeads() * Return array of all leads in RepairShopr
  • recordLead(leadData) * Records a new lead in repairshopr with the given leadData
import RS from 'rs-leads-api';
let l = {
	firstname:String,
	lastname:String,
	email:String,
	phone:String,
	location:String,
	make:String,
	model:String,
	issue:String,
	price:String,
}
RS.recordLead(l).then((e,l)=>{
	if(!e) console.log(l)
	else console.log(e)
})

Simple Example with Express.js

import express from 'express';
import RS from 'rs-leads-api';
const app = express();
app.get('/getLeads',async(req,res)=>{
	try{
		let leads = await RS.getLeads()
		res.send(leads)
	}
	catch(e){
		console.log(e)
		res.send(false)
	}
});
app.get('/getCustomerID/:first/:last',async(req,res)=>{
	try{
		let query = `${req.params.first} ${req.params.last}`
		let ID= await RS.getCustomerID(query)
		res.send(ID)
	}
	catch(e){
		console.log(e)
		res.send(false)
	}
});
app.post('/recordCustomer',async(req,res)=>{
	try{
		let customer = await RS.recordCustomer(req.body)
		res.send(customer)
	}
	catch(e){
		console.log(e)
		res.send(false)
	}
});
app.post('/recordLead',async(req,res)=>{
	try{
		let lead= await RS.recordLead(req.body)
		res.send(lead)
	}
	catch(e){
		console.log(e)
		res.send(false)
	}
});
app.listen(process.env.PORT||3000,()=>console.log('Server started...')
  

STORES Environment Variable

In order to record the leads for the correct locations, you will need a STORES variable. This is a JSON object that has been stringified. To generate this variable, you will need to make an object with the locations exact name in RepairShopr and the location_id, which can be found at : https://<your-subdomain>.repairshopr.com/locations Once you have this information, you should build an object like the following, then stringify it using any means (like this one). The resulting string is what you should add to your environment variables as STORES

Example STORES JSON Object:
{
2126:"Store Name 1",
2127:"Store Name 2",
2128:"Store Name 3"
}

Exmple ENV variable STORES = '{"2126":"Store Name 1","2127":"Store Name 2","2128":"Store Name 3",}'

0.4.0

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago