7shifts integrated time clock

So I have integrated 7 shifts into SambaPOS and using it along the time clock Emre had built recently. It works really well I will share it with you here.

For those wondering about the time clock here it is: Time Clock.zip (10.4 KB)

This is a configuration task you will import using DB Tools in Settings. Once imported you go to Settings > Configuration Tasks and click on Time Clock.


First thing you will need is the script:
You can ignore Method 2 they removed that method from their api because they want it for internal use only (Bastards) anyway.

var apikey = 'YOUR API KEY HERE'; 
var method1 = 'locations';
var method2 = 'time_punches/punch';
var method3 = 'time_punches';
var method4 = 'users';

function getuser(pincode) {
  var getusers = web.PostData('https://api.7shifts.com/v1/'+method4+'/','',''+apikey+'','');
  var user = JSON.parse(getusers);
  for(var i=0; i<user.data.length; i++){
   if(user.data[i].user.employee_id == pincode)
   return user.data[i].user.id;

function getlocation() {
  var location = web.PostData('https://api.7shifts.com/v1/locations','',''+apikey+'','');
  var getlocations = JSON.parse(location);
  return getlocations.data[0].location.id;

function punch(pincode,timein,timeout) {
  var eid = getuser(pincode);
  var loc = getlocation();
  var execpunch = web.PostJson('https://api.7shifts.com/v1/'+method3+'/','{ "time_punch": { "user_id": '+eid+', "location_id": '+loc+', "clocked_in": "'+timein+'", "clocked_out": "'+timeout+'" } }',''+apikey+'','');
  var getpid = JSON.parse(execpunch);
  return getpid.data.time_punch.id;


All you need to do is create an Execute Script action:


Add the action as the first one in this Rule:

Put this in for function variable:

7shiftcreate.punch('{REPORT SQL DETAILS:SELECT PinCode FROM Users WHERE Name ='{SETTING:CURRENTUSER}':F.PinCode}','[=FD(ADS('{REPORT OPEN TASK DETAILS:=FD([T.StartDate],'yyyy-MM-dd'),T.StartTime,:(TSC.User={SETTING:CURRENTUSER}) and (TST=Punch):{0} {1}}',+18000),'yyyy-MM-dd HH:mm:ss')]','[=FD(ADS('{DATE:yyyy-MM-dd HH:mm:ss}',+18000),'yyyy-MM-dd HH:mm:ss')]')

Now what is important is in that script call you have to offset the timezone difference with yours and 7shifts servers they refuse to fix that issue. In my case i had a +5 hour difference so you will see I added 18000 seconds. Just replace the 18000 with whatever offset you need from their servers.


That is it really other than opening 7 shifts account and getting your API key.

Whatever Pin you set for users in SambaPOS is the pin that needs to be set for 7shifts.


What this does is it records the punch when the user clocks out for the day. The reason for this is because of how the Create method in 7shifts API works. You want to do the punch in and out at the same time or else its even more complicated with needing to use 2 calls one to create and one to update.

It uses the task from the SambaPOS time clock for the punch in time and then just uses current date/time for punch out.


Next up is how to sync SambaPOS sales into 7shifts for forecasting. They recently opened up the API for that.


Eventually I will spend the time to completely integrate it where SambaPOS reads punches from 7shifts for reports etc and it will be fully synced even when editing punches from inside SambaPOS. I would also like to fully sync the scheduling portion of it so we can do some cool automation in SambaPOS based on employee schedules. Like not allowing someone to clock in or use the pos if they are not scheduled etc.


Thank you @Jesse for sharing your integration.

1 Like

I have made some changes to this integration. I will post them tomorrow. I also have integrated Sales to 7shifts so we can track labor %. I need a few features to complete time punching though so maybe @VehbiEmiroglu can help me with that eventually. I specifically need the ability to use PUT method to update punches vs POST method.

1 Like

How you post sales ?

I’ll share that one moment.

1 Like

@VehbiEmiroglu Before I share that I want to clarify. I need the PUT method for JSON something like web.PutJson to execute Punch Updates on the 7shifts API. web.PostJson does not want to work.

Ok getting my sales integration script ill post it here…

1 Like

Here is my script for posting sales:

var apikey = 'YOURAPIKEYHERE'; 
var method1 = 'locations';
var method2 = 'time_punches';
var method3 = 'users';
var method4 = 'receipts';

function createReceipt(ttotal,date,tid) {
	var create = web.PostJson('https://api.7shifts.com/v1/'+method4+'/','{ "receipt": { "total": '+ttotal+',"open_date": "'+date+'", "location_id": 25721, "external_id": '+tid+'}}',''+apikey+'','');
	return create;

I hardcoded locationid but you wouldnt need to do that. You can query their api to get locationid.

1 Like

The Rule:

7shifts.createReceipt('[=TN('{PLAIN TOTAL}')*100]','[=FD(ADS('{TICKET DATE:yyyy-MM-dd HH:mm:ss}',+18000),'yyyy-MM-dd HH:mm:ss')]','{TICKET ID}')
1 Like

I had to format the date/time punches for an offset of 6 hours due to their api server not making that adjustment.

1 Like

As you can see it submits receipts to 7shifts after every transaction.

1 Like

@Jesse wouldnt opening a past ticket from ticket list to reprint bill or something submit it a second time?
You want some form of mark on submitted tickets? My PMS intergration I set a state with the carge ids returned from the API and use this as an extra validation to ensure it never gets double posted.

No it would not. It has ticket id assigned and it only allows it to post once via that ticket id. The ticket id is the unique identifier. I mean on their API side I used TICKET ID as the unique identifier so it will only allow the receipt with that ID once. There is a different API command for updating existing tickets. I need PUT capability for that as well. POST wont work.

So as of right now my sales integration is missing the capability to update returns or refunds etc.

1 Like