Let the platform do the work

How to Fetch the Current Users Time

Overview

An example in bash script demonstrating how to fetch the current users time with the v11 /ping/whattimeisit REST GET endpoint.

Authenticating

First, you will need to authenticate to the Sugar API. An example is shown below:

  curl -X POST -H Cache-Control:no-cache -H "Content-Type: application/json" -d '{ 
 "grant_type":"password",
 "client_id":"sugar",
 "client_secret":"",
 "username":"admin",
 "password":"password",
 "platform":"custom_api"
}' https://{site_url}/rest/v11/oauth2/token

More information on authenticating can be found in the How to Authenticate and Log Out example and /oauth2/logout endpoint documentation.

Getting the Current Time and Date for the User

Next, we can get the current time and date using the /ping/whattimeisit endpoint.

  curl -s -X GET -H OAuth-Token:{access_token} -H Cache-Control:no-cache https://{site_url}/rest/v11/ping/whattimeisit

Response

  "2017-11-03T06:45:59-07:00"