I've written a Google Apps Script function that shortens the URL using Firebase's Dynamic Links -
function fbURLShort() {
var data = {
"dynamicLinkInfo": {
"domainUriPrefix": "https://example.page.link",
"link": "https://example.com/lenghtlyURL?with=hooks&more=additions"
},
"suffix": {
"option": "SHORT"
}
};
var url = "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=myAPIkey"
var options = {
'method': 'POST',
"contentType": "application/json",
'payload': JSON.stringify(data),
"muteHttpExceptions":true
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response)
var json = response.getContentText();
var data = JSON.parse(json);
var obj = data["shortLink"];
Logger.log(obj)
}
This works perfectly well when using the example.page.link domainUriPrefix; however, there is also a way to Connect a custom domain and I've been able to successfully do that too (this domain would show up under Firebase's Hosting section).
However, when I replace example.page.link with customdomain.com, it throws the following error -
"error": {
"code": 400,
"message": "Your project does not own Dynamic Links domain: https://customdomain.com [https://firebase.google.com/docs/dynamic-links/rest#create_a_short_link_from_parameters]",
"status": "INVALID_ARGUMENT"
}
Now, what I want to do is use said custom domain as a base link to shorten URLs instead of .page.link (via Dynamic Links). How do I go about doing that?