I can expand the url, do the search/replace and then again shorten the url.
Can you tell me which API do you want to use to shorten the url in the last step.
Though my profile is new here, I have been working in this field since last 7 years.
Thanks & Regards,
Rinku K.