REST API Requests via JS

Hi everybody!

We are trying to port a custom module from Sugar 7 to Suite. In this module we have Javascript that makes calls to the REST API to fetch and relate beans as needed.

In Sugar 7 we use SUGAR.App.api.call() to make these API calls, but I failed to find an alternative to this in Suite (at least I could not find anything in the documentation or the SUGAR JS object). So I tried to use AJAX calls to the REST v4 API endpoint using the session stored within the PHPSESSID cookie, but no matter how I make the request I always get ‘Invalid session ID’ as a response (guess the session is not valid for the API?). I am also logged out of Suite afterwards.

If I use the login request and make the same request with the resulting session ID the request goes through correctly. But that would require knowing the current users username + password in the JS code, which I don’t (storing it in the browser would be a bad idea anyways…).

Is there any way to enable me to make REST API calls in JS using the current session, without needing to reauthenticate?

Thanks in advance.

1 Like