Quick question about mapping survey responses to specific interactions.
I am using the Python SDK to fetch completed surveys via client.quality_api.get_quality_surveys. The response contains the survey ID but the interaction_id field is null. I need to correlate these CSAT scores with Genesys Cloud interactions for Salesforce case updates. My current code uses a nested loop to match by timestamp, which is inefficient. Here is the payload I receive. How can I retrieve the direct interaction reference?
Have you tried inspecting the OpenAPI spec definition for SurveyResponse directly? The interactionId field is not populated in the survey list endpoint because it is a derived property, not a stored one in the survey table. The spec shows this field is only available when you fetch the specific survey response details using the get_quality_survey_response method. You need to iterate through the survey IDs from the initial list call and fetch each response individually to get the interactionId. This is a common pattern in the Genesys Cloud API where list endpoints return minimal data and detail endpoints return full context. The Python SDK follows this structure strictly. Here is the correct approach to fetch the interaction ID for each survey response:
from genesyscloud.platform.client import PlatformClient
from genesyscloud.quality.api import quality_api
def fetch_survey_interaction_ids(client, org_id):
# First, get the list of surveys
surveys, response = quality_api.get_quality_surveys(
client,
org_id=org_id,
expand=['response']
)
interaction_ids = []
for survey in surveys.resources:
# Fetch individual survey response to get interactionId
survey_response, _ = quality_api.get_quality_survey_response(
client,
survey_response_id=survey.id,
org_id=org_id
)
if survey_response and survey_response.interaction_id:
interaction_ids.append(survey_response.interaction_id)
return interaction_ids
This approach ensures you get the correct mapping without relying on timestamp matching. The spec clearly defines this relationship, and the SDK auto-generation respects these distinctions. Always check the model definitions in the OpenAPI spec when fields appear null in list responses.
Make sure you are not blocking the main thread with synchronous API calls in a tight loop. The suggestion above is technically correct regarding the data location, but your implementation approach is dangerous. Fetching individual survey responses sequentially via get_quality_survey_response inside a loop will cause rate limit hits (429s) or timeout errors if you have high volume. You need to batch these requests or use the Notification API to listen for survey completion events instead of polling.
Here is a safer pattern using asyncio for parallel execution to avoid blocking:
import asyncio
from purecloudplatformclientv2 import QualityApi
async def fetch_interaction_ids(survey_ids, api_instance):
tasks = [api_instance.get_quality_survey_response(s_id) for s_id in survey_ids]
results = await asyncio.gather(*tasks, return_exceptions=True)
valid_interactions = [r.interaction_id for r in results if not isinstance(r, Exception) and r.interaction_id]
return valid_interactions
Polling endpoints aggressively is a bad habit. Switch to event-driven architecture if possible.
As far as I remember, the interaction ID is available directly in the survey response entity when fetched individually, so the loop approach is necessary but needs rate limit handling.
“interaction_id field is null”
The Python SDK does not support batch fetching for survey responses, so you must implement exponential backoff or parallel execution with asyncio to avoid 429s.
Ah, yeah, this is a known issue… the query endpoint silently drops unknown filters. use the specific interaction endpoint instead.
get /api/v2/quality/evaluations?interactionId={{id}}
include quality:eval:read in your scopes.
the problem with looping through individual survey responses is not just rate limits. it is the data latency. the interaction_id field is often null until the evaluation record is fully persisted, which can take minutes. if you are trying to map this for real-time salesforce updates, you will fail.
here is a safer postman pre-request script to handle the oauth token refresh before hitting the evaluation endpoint, ensuring you don’t get 401s during the loop: