Skip to main content

Hi, I’m new to FME, looking to setup a python caller to manipulate some feature services on our Enterprise portal.

Is it possible to call feature services from within a python caller inside a workspace hosted by FME Flow?

The script below works fine in FME Workbench and prints True, the FME Flow prints false.

 

import fme
import fmeobjects
import arcpy
from arcgis.gis import GIS
from arcgis.features import FeatureLayer

def ProcessWebhook(feature):
        # URL to AGOL or Portal
        url_gis = "https://<servername>/portal" # URL to AGOL or Portal
        user = "xxxx" # AGOL or Portal username
        pwd = "xxxx" # user password
        gis = GIS(url_gis, user, pwd)

        id = feature.getAttribute('webhook_feat_id')
        whereclause = 'field_3 = ' + "'" + str(id) + "'"

        in_feat_url = r"https://<servername>/hostedserver/rest/services/Hosted/service_3c55880fb4112b08f2af29c22e/FeatureServer/0"
        in_feat_fl = FeatureLayer(in_feat_url)
        in_feat = in_feat_fl.url

        out_feat_url = r"https://<servername>/server/rest/services/Test/Form1/FeatureServer/0"
        out_feat_fl = FeatureLayer(out_feat_url)
        out_feat = out_feat_fl.url

        # check that feature services are available
        if all(arcpy.Exists(lyr) for lyr in in_feat, out_feat]):
            
            in_feat_sel = arcpy.management.SelectLayerByAttribute(
                in_layer_or_view=in_feat,
                selection_type="NEW_SELECTION",
                where_clause=whereclause,
                invert_where_clause=None
                )

            arcpy.management.Append(
                inputs=in_feat_sel,
                target=out_feat,
                schema_type="NO_TEST",
        field_mapping="",
                subtype="",
                expression="",
                match_fields=None,
                update_geometry="NOT_UPDATE_GEOMETRY"
            )

            print(True)
        else:
            print(False)

 

Thanks for any pointers.

Regards,

Elliott

Yes it is possible but there has to be an Esri product installation on Flow that has the correct version of ArcPy and for some versions of Flow, has to be installed a certain way.

Can you post the actual error?


There’s no error, it just doesn’t recognize the feature services I’ve requested in the python script line: 

        if all(arcpy.Exists(lyr) for lyr in fin_feat, out_feat]):

            print(True)
        else:
            print(False)

Any direction on what is required by FME Flow to allow the usage of Portal Feature Services in a python call would be of great help.

I don’t know much about FME Workbench (2023.2) and FME Flow (2023.2.2 - Win64). 

Below is the simple Workbench profile.

Workbench output

Server Job output

Regards,

Elliott


I’ve added a try catch block and removed the checking the layers exist to see what the error could be, just says it doesn't exist or is not supported. Not sure where to go from here.

I can connect to the the feature service out side of the python caller, just not inside of it.

 


You need to use the ArcGIS Python API to open the feature services. Look at this pages, it explains serveral ways to access feature services in ArcGIS Enterpriise or AGOL.
Working with Feature Layers and Features | ArcGIS API for Python

 


Thanks for the help and guidance, I was trying to use standard arcpy toolbox calls to do my work instead of using ArcGIS API as you suggested.

 

Very much appreciated,

Elliott 


Reply