SambaPOS/Google Calendar Api?

I’ve asked this question before and got no response. What is the purpose of the Google Calendar Api. I’ve enabled it but what next? I presume I need some kind of script to communicate with Google Calendar. I am totally confused about the API side of SambaPOS. I’ve looked at the postcode api and the way it pulls information into SambaPOS but that is receiving data. Can I send data to samba?. I know we have the below but it means nothing to me without an example on how it works. Most posts i have clicked on with anything to do with API i dont have permission to view it. I just dont get the point of having the Google Calendar in Samba Market when no one knows how to use it. Maybe @emre can help??

api.EntityType(name).Create(entityName,[defaultStates])
api.EntityType(name).Entities().State(name).Update(value);
api.EntityType(name).Exists();
api.EntityType(name).Fields(name).Exists();
api.EntityType(name).Fields(name).FindEntityName(searchValue);
api.EntityType(name).Fields(name).Create(fieldtype,[format],[valuesource],[hidden]);

api.Entity(name).State(name).Update(state);
api.Entity(name).State(name).Get();
api.Entity(name).Data(name).Update(value);
api.Entity(name).Data(name).Get();
api.Entity(name).Exists();
api.Entity(name).Create(entityTypeName);

You should look at googles website for how to connect and use it. You will need to use jscript to access and use it. I will post a few simple things to get you started but be patient while I prepare it please.

PS most people don’t know how to use a lot of the advanced stuff because they don’t spend the time exploring it. This is very advanced techie kind of configuration so not many have attempted it. In fact only a few of us have contributed to scripting. Most people wait for us to do something so they can just copy it.

Here is a discussion we had in Beta. This was posted from Emre I looked and it seems it was not put out for public to see so sorry for that we tried to get as much out as possible but few things slipped by.

Google Calendar add-on added to allow access Google Calendar API via JScript. That addon publishes the .net wrapper lib for Google Calendar API released by Google.

##Usage

function ListCalendars()
{
  var service = googleCalendar.GetService('your cliend Id',' your client secret');
  var list = service.CalendarList.List().Execute().Items.ToArr();
  var result = '';

  for (var i = 0; i < list.length; i++)
  {
      result += list[i].Summary+'-';
  }
 
  return result;
}

googleCalendar.GetService(id,secret) method returns a service object. You can use this object to access API Resources.

##How to build API call methods

https://developers.google.com/google-apps/calendar/v3/reference/ documentation lists available service resources. I’ll show you how to build your API call methods with that document.

As shown on the document there is CalendarList resource. That means I can access resource with service.CalendarList. Clicking on it will display details.

CalendarList resource supports List() method. To execute that method I’ll use service.CalendarList.List().Execute().

Clicking on it shows what it returns.

It returns calendars with Items property. So we can call it like…

var calendars = service.CalendarList.List().Execute().Items;

In our example our method call ends with ToArr() method. That method converts Items collection to a JScript Array so we can access it’s items with [x] indexers inside for loops. As a general rule you can convert any collection to an Array with that method.

I’ve added this code as a Script so I can access it with {CALL:X} tag.

{CALL:cal.ListCalendars()} does nothing useful. It only returns calendar names separated by minus character.

You’ll notice I’ve used Summary property to read Calendar’s summary. CalendarList.List().Execute().Items returns a Collection of calendarListEntry objects. To learn what properties calendarListEntry object have click on calendarList link on Response page.

You can see all properties of calendarListEntry

##Creating ClientId and ClientSecret keys.

Finally you’ll need a clientId and clientSecret to be able to access Google API’s. If you never did that before visit Google Developers Console, create new app and enable Google Calendar API from API’s section.

From Credentials section create a new OAuth Client ID and use your client Id and client secret values while calling googleCalendar.GetService() method.


In Summary…

  1. Visit Google Developer Console and create a new project. https://developers.google.com/console/help/new/
  2. Enable Google Calendar API.
  3. Create OAuth Client ID and copy keys.
  4. Create a new script and add sample code inside. Use your keys to create service.
  5. Use Calendar API documentation to construct API calls. https://developers.google.com/google-apps/calendar/v3/reference/
  6. Use {CALL:X} tag to execute api calls.
3 Likes