A simple REST API integration in Salesforce for URL Shortner
URL Shortner
URL Shortner takes long URLs and squeezes them into fewer characters to make a link that is easier to share, tweet, or email to friends. Users can create these short links through the web interface at goo.gl, or they can programatically create them through the URL Shortener API.
REST API
A RESTful API is an application program interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data. A RESTful API -- also referred to as a RESTful web service -- is based on representational state transfer (REST) technology, an architectural style and approach to communications often used in web services development. In this blog, a REST API for URL Shortner provided by Google is going to be used. When an account is created/updated with the website field, an API call is made to get the shorten URL and update it back in the website field in Account.
Future Annotation
Future annotation to identify methods that are executed asynchronously. When you specify future, the method executes when Salesforce has available resources. The future annotation can be used when making an asynchronous Web service callout to an external service. Without the annotation, the Web service callout is made from the same thread that is executing the Apex code, and no additional processing can occur until the callout is complete
To know more about, Future annotation https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_future.htm
Follow the below step:
1) Sign up for google account.
2) Enable to Google URL Shortner API
3) You can use either way of authentication oauth or API Key. In this blog, we are using the API key.
Use the below link to perform the above step.
https://developers.google.com/url-shortener/v1/getting_started
In Salesforce, add the Google API's endpoint in the remote site settings. (How to add remote site settings)
URL Shortner takes long URLs and squeezes them into fewer characters to make a link that is easier to share, tweet, or email to friends. Users can create these short links through the web interface at goo.gl, or they can programatically create them through the URL Shortener API.
REST API
A RESTful API is an application program interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data. A RESTful API -- also referred to as a RESTful web service -- is based on representational state transfer (REST) technology, an architectural style and approach to communications often used in web services development. In this blog, a REST API for URL Shortner provided by Google is going to be used. When an account is created/updated with the website field, an API call is made to get the shorten URL and update it back in the website field in Account.
Future Annotation
Future annotation to identify methods that are executed asynchronously. When you specify future, the method executes when Salesforce has available resources. The future annotation can be used when making an asynchronous Web service callout to an external service. Without the annotation, the Web service callout is made from the same thread that is executing the Apex code, and no additional processing can occur until the callout is complete
To know more about, Future annotation https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_future.htm
Follow the below step:
1) Sign up for google account.
2) Enable to Google URL Shortner API
3) You can use either way of authentication oauth or API Key. In this blog, we are using the API key.
Use the below link to perform the above step.
https://developers.google.com/url-shortener/v1/getting_started
In Salesforce, add the Google API's endpoint in the remote site settings. (How to add remote site settings)
This comment has been removed by the author.
ReplyDeleteGood news and info! I am finding free url shortener. If you know about it , please share.
ReplyDeleteThanks a lot
I can offer great communication and development process (GIT, Jira, Trello, Slack, daily Skype and Google Hangouts calls, etc.) I am interested in long term relationship so please get in touch to discuss the details.
ReplyDeleteAPI Integration Expert
This article is brimming with information about the salesforce service cloud for more like this. I have additionally discovered an article anybody can check Salesforce Service Cloud , for more data, it was knowingly more instructive. You may discover more insights regarding it here.
ReplyDelete