7shifts Integration Time Clock and Sales

Sometimes the import tool messes with it.

Paste the script here minus your key

Should there be anything before the “var” characters?

Like at the very top of the script?

Just did, view the screenshot above

No that parts fine…

Ok you have old scripts. One sec I must have not put new file up

1 Like
ar apikey = 'APIPASTED HERE'; 
var method1 = 'time_punches';
var method2 = 'users';
var method3 = 'receipts';

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 getuser(pincode) {
  var getusers = web.PostData('https://api.7shifts.com/v1/'+method2+'/','',''+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 punch(userpin,pmethod,timein) {
	var loc = getlocation();
	var userid = getuser(userpin);
 	var execpunch = web.PostJson('https://api.7shifts.com/v1/'+method1+'/','{ "time_punch": { "user_id": '+userid+', "location_id": '+loc+', "'+pmethod+'": "'+timein+'"}}',''+apikey+'','');
 	var punchid = JSON.parse(execpunch);
	var punchidresult = punchid.data.time_punch.id;
 	return punchidresult;

function updatepunch(punchid,punchtype,time) {
	var update = web.PutJson('https://api.7shifts.com/v1/'+method1+'/'+punchid+'','{ "time_punch": { "'+punchtype+'": "'+time+'"}}',''+apikey+'','');
	return update;

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

I had location id hardcoded in that one. It won’t work for you. New one had a function to get your location id.

No wait that’s right one. Hmm let me look closer.

Are you using SQL express 2017? Actually nm that shouldn’t matter. Hmm it’s gotta be a simple typo

Are you using beta 5.2.23? That is required.

Yep. I just downloaded the latest Beta version. Currently shows Beta 114.
Currently using SQL 2017 express as well

Does the code match what you have in your current script?

Try taking the sales script out for now. Your on 5.2.23 right?

Im pretty certain i am.

Am i meant to type something specific in the bar next to the Test button?

I removed the sales part but still gives me a syntax error.

I double checked the whole code to ensure im not missing any ‘;’ and can confirm they are all there.

Is the code you have in your tutorial the updated one I can maybe try?

If you try to punch in it doesn’t work?


Here is me clocking in now…

I refreshed 7 Shift.

New punch is not there.

Do the names also have to match? or are the punches the only Unique thing that has to match in Samba and in 7shift?