This topic provides step-by-step instructions for configuring network rules, external access integration, and a user-defined function (UDF) to enable secure access to the Precisely Gateway API from Snowflake Pipeline Engines.
Prerequisites
You must have account administrator privileges in Snowflake to perform the setup steps described in this guide.
Step 1: Create or Replace Network Rule
Run the following statements to create or replace the network rule:
CREATE OR REPLACE NETWORK RULE PRECISELY_NETWORK_RULE
MODE = EGRESS
TYPE = HOST_PORT
VALUE_LIST = (
-- Precisely API hosts
'api.cloud.precisely.com',
'api.eu1.cloud.precisely.com',
'api.au1.cloud.precisely.com',
'api.gb1.cloud.precisely.com',
-- Third-party API host, add as required
'api.openweathermap.org'
); Step 2: Create or Replace External Access Integration
Run the following statements to create or replace the external access integration:
CREATE OR REPLACE EXTERNAL ACCESS INTEGRATION PRECISELY_API_INTEGRATION
ALLOWED_NETWORK_RULES = (PRECISELY_NETWORK_RULE)
ENABLED=TRUE; Step 3: Create or Replace UDF PRECISELY_API_CALL
Create or replace the function CREATE OR REPLACE FUNCTION
PRECISELY_API_CALL(API_CONTEXT VARIANT) with the following function
definition:
CREATE OR REPLACE FUNCTION PRECISELY_API_CALL(API_CONTEXT VARIANT)
RETURNS VARIANT
LANGUAGE PYTHON
RUNTIME_VERSION = 3.12
HANDLER = 'compute'
EXTERNAL_ACCESS_INTEGRATIONS = (PRECISELY_API_INTEGRATION)
PACKAGES = ('requests')
AS
$$
import requests
def compute(api_context: dict) -> dict:
ctx = api_context if isinstance(api_context, dict) else {}
try:
base_url = (ctx.get('baseUrl') or '').rstrip('/')
endpoint_path = (ctx.get('endpoint') or '').lstrip('/')
request_url = f'{base_url}/{endpoint_path}' if endpoint_path else base_url
http_method = (ctx.get('method') or 'POST').upper()
request_kwargs = {
'method': http_method,
'url': request_url,
'headers': dict(ctx.get('headers') or {}),
'timeout': (10, 30),
}
if http_method in ('POST', 'PUT', 'PATCH'):
request_kwargs['json'] = ctx.get('body')
with requests.Session() as http_session:
response = http_session.request(**request_kwargs)
response.raise_for_status()
try:
return response.json()
except ValueError:
return {'raw_response': response.text, 'status_code': response.status_code}
except requests.HTTPError as http_error:
status_code = http_error.response.status_code if http_error.response else None
return {'error': str(http_error), 'status_code': status_code}
except Exception as unexpected_error:
return {'error': str(unexpected_error), 'status_code': None}
$$;Post-Configuration
After completing these steps, your Snowflake account will be configured to securely access the Precisely Gateway API using the provided UDF. Ensure that only authorized users and roles have access to the UDF and external access integration for security purposes.