def generateFBEOnboardingURL()

in fb_metadata/utils/fbe.py [0:0]


def generateFBEOnboardingURL(metadata: FacebookMetadata):
    """
    This method generates the FBE Onboarding URL to start the FBE Onboarding flow

    params:
    metadata: The FacebookMetadata object for the store that should be onboarded

    returns:
    the url for FBE onboarding
    """
    # permissions to grant FB
    # Optionally, you can also use the "manage_business_extension,ads_management" permissions here
    # as stated in the FBE documentation
    # https://developers.facebook.com/docs/marketing-api/fbe/fbe2/guides/authentication#biz_login_via_url
    _SCOPE = "manage_business_extension,catalog_management"

    # build the json obj to be serialized for url
    extras = {
        "setup": {
            "external_business_id": metadata.fbe_external_business_id,
            "timezone": metadata.fbe_timezone,
            "currency": metadata.fbe_currency,
            "business_vertical": metadata.fbe_business_vertical,
            "domain": settings.DOMAIN,
            "channel": "COMMERCE",
            "test_config": {
                "test_commerce_account": True,
            },
        },
        "business_config": {
            "business": {"name": metadata.store.name},
            "page_shop": {"enabled": True, "visible_product_count": 5},
        },
        "repeat": False,
    }
    print("FBE Extras:", extras)

    # turn our object into json string for the URL
    extras_string = json.dumps(extras)

    # the state string helps us match our fb metadata object to the shop after callback
    state_string = "fbe_external_business_id=" + metadata.fbe_external_business_id

    # substitute values into the FBE_ONBOARDING_URL string
    fb_url = settings.FBE_ONBOARDING_URL.format(
        settings.APP_ID,
        settings.REDIRECT_URI,
        _SCOPE,
        state_string,
        extras_string,
    )

    return fb_url