2

This question is about what I think is a discrepancy between the REST API (from the docs anyway), and the behaviour afforded through the Firebase console.

Here's the console:

enter image description here enter image description here

Yet when I look at the REST API docs, I don't see any way to follow step (1) from the Firebase console. I don't see any way to set up a short URL link, rather it looks like it will be generated. This is a shame because I wanted to generate guessable links. For reference, here is their specification sans platform-specific info keys (eg "iosInfo"):

{
  "dynamicLinkInfo": {
    "domainUriPrefix": string,
    "link": string,
  },
  "suffix": {
    "option": "SHORT" or "UNGUESSABLE"
  }
}

Is there a way to copy the console behaviour through the API?

Ruben
  • 541
  • 6
  • 14

3 Answers3

4

I was able to create persisting link in firebase dynamic link using API in node. I did the following.

  1. Create oauth2 client
import {google} from "googleapis";

const oauth2Client = new google.auth.GoogleAuth({
    keyFile: "path to service account json file",
    scopes: ['https://www.googleapis.com/auth/firebase']
})
  1. Create link data object
    const data = {
        "dynamicLinkInfo": {
            "domainUriPrefix": "https://myapp.page.link",
            "link": "my deeplink",
            "androidInfo": {
                "androidFallbackLink": "",
                "androidLink": "",
                "androidMinPackageVersionCode": "",
                "androidPackageName": bundleName // android package name, fe my.app.io
            },
            "iosInfo": {
                "iosAppStoreId": `${isi}`, // app store app id
                "iosBundleId": bundleName, // ios app bundle id, fe my.app.io
                "iosCustomScheme": "",
                "iosFallbackLink": "",
                "iosIpadBundleId": "",
                "iosIpadFallbackLink": ""
            },
            "navigationInfo": {
                "enableForcedRedirect": false
            },
            "analyticsInfo": {
                "googlePlayAnalytics": {
                    "utmCampaign": "",
                    "utmMedium": "",
                    "utmSource": ""
                },
                "itunesConnectAnalytics": {
                    "at": "",
                    "ct": "",
                    "mt": "",
                    "pt": ""
                }
            },

            "socialMetaTagInfo": {
                "socialDescription": "",
                "socialImageLink": "",
                "socialTitle": ""
            },
        },
        "name": "Link name column from FDL",
        "suffix": {
            "customSuffix": "URL_prefix_during_link_creation_from_FDL, "option": "CUSTOM"
        }
    }
  1. Call the API
oauth2Client.request({
        method: "POST",
        url: "https://firebasedynamiclinks.googleapis.com/v1/managedShortLinks:create",
        data: data
    })

Links:

As far as I know, you cannot use any direct REST API since you need appropriate oauth2 access_token for specific scope. I was trying to spoof FDL requests and reflect it behaviour without success, but this works.

lisek
  • 267
  • 4
  • 16
  • 1
    Now this is _very_ interesting. The `CUSTOM` option is not documented everywhere, but it _is_ documented in the [Node.js API you linked](https://googleapis.dev/nodejs/googleapis/44.0.0/firebasedynamiclinks/classes/Resource$Managedshortlinks.html#source) and looks exactly like what I was looking for. – Ruben Dec 14 '21 at 18:34
  • But you cannot use API from FDL rest API doc because it says custom suffix is not supported. There is some mess around it. – lisek Dec 15 '21 at 20:12
  • For anyone wondering, if you put the above solution in Firebase Functions, you don't need to specify the service account `keyFile`. The only other difference is the way you import googleapis: `const {google} = require('googleapis');` – Peter Keefe Nov 01 '22 at 19:34
0

It's not possible to set custom suffix for short links created through API. If you have more details for your use case, I suggest filing it as a feature request https://firebase.google.com/support

Omatt
  • 8,564
  • 2
  • 42
  • 144
0

It is possible to set custom suffixes for short links created. We call it Managed Short Links.

Use the approach suggested by lisek, and for understanding here are the links to the latest docs from google dev.

  1. https://googleapis.dev/nodejs/googleapis/latest/firebasedynamiclinks/interfaces/Schema$CreateManagedShortLinkRequest.html
  2. https://googleapis.dev/nodejs/googleapis/latest/firebasedynamiclinks/classes/Resource$Managedshortlinks.html#source