Welcome to the final article in our SData 2.0 in Sage CRM series. In the previous parts, we covered querying, updating, inserting, and deleting records using SData 2.0. Now, let’s explore an important aspect of working with the API—authentication.
Depending on your environment and use case, there are multiple authentication methods available for accessing SData 2.0. In this post, we’ll review the pros and cons of each method and guide you on when to use them.
Basic Authentication is the most straightforward method, where you use Sage CRM login credentials to authenticate each request. This method requires sending the user's credentials (username and password) with every API request.
Basic Authentication is ideal when your application needs user-specific actions, ensuring that each user's permissions and rights are respected. It’s also useful when tracking actions back to individual users is important for accountability.
An alternative to having each user authenticate is creating a dedicated user account solely for handling SData requests. This approach simplifies access by funneling all API calls through a single user.
If user-specific actions aren't required, and you prefer a simpler configuration, a dedicated user account can centralize all SData calls under one login, reducing complexity.
A more seamless method is to authenticate using a Session ID (SID). This method passes an active session token to authenticate API requests without needing credentials for each call. The session ID can be retrieved within the current session of Sage CRM and appended to SData URLs.
To retrieve the SID, you can use JavaScript within Sage CRM:
crm.CurrentUser.sid
This will output the current session ID, which can be appended to your SData requests:
GET http://{ServerName}/sdata/{InstallName}j/sagecrm2/-/Company?SID={YourSessionID}
This method is ideal when you already have an active session within Sage CRM (e.g., during a logged-in session in the CRM’s interface) and you want to avoid repeatedly entering credentials.
Selecting the correct authentication method for SData 2.0 depends on your specific use case and environment. Here's a quick guide to help you choose:
Throughout this series, we’ve explored the powerful capabilities of SData 2.0 in Sage CRM, covering everything from querying and manipulating data to managing authentication. By choosing the appropriate authentication method, you can ensure your integration with Sage CRM is both secure and efficient.
We hope you found this series insightful and that it equips you with the knowledge needed to work confidently with SData 2.0 in your own projects. If you have further questions or need assistance with your integration, feel free to reach out!
Stay tuned for more content, and don’t hesitate to explore other ways to extend Sage CRM functionality!