“Cannot read property ‘toLowerCase’ of undefined” - that’s what’s popping up in the console, and honestly, I’m a bit lost. It’s happening when we try to parse the response from a Data Action in the Embeddable Framework. We’re on Genesys Cloud, and I’m… pretty sure the JSONPath is correct, but maybe not? It feels like something’s escaping wrong.
The Architect flow is pretty simple. It’s just taking a digit collected from the phone number - a simple DTMF collection - and using that to look up a customer ID in a third-party system. The Data Action uses a POST request to /api/v2/dataactions/YOUR_DATA_ACTION_ID, and the response is supposed to return the customer details as JSON. The JSONPath expression we’re using is $.customer.id. I think that should work.
Here’s the relevant bit of the React component where we’re pulling the data from the Embeddable Framework, and trying to render it. Apologies if this is really basic stuff, I’m still getting my head around the whole component lifecycle thing.
import React, { useState, useEffect } from 'react';
import { useDataAction } from '@genesyscloud/embeddable-framework';
function CustomerDetails({ dataActionId, digitCollected }) {
const [customerId, setCustomerId] = useState(null);
const { data, loading, error } = useDataAction(dataActionId, { digit: digitCollected });
useEffect(() => {
if (data && data.customer && data.customer.id) {
setCustomerId(data.customer.id);
}
}, [data]);
if (loading) return <p>Loading customer details...</p>;
if (error) return <p>Error loading customer details: {error.message}</p>;
return (
<div>
{customerId ? <p>Customer ID: {customerId}</p> : <p>Customer ID not found.</p>}
</div>
);
}
export default CustomerDetails;
The weird part is that the response looks okay in the network tab. It’s valid JSON, and the customer.id field is definitely there. But the useDataAction hook seems to be getting something that’s… not quite right. The error happens when it tries to call toLowerCase() on something that’s undefined. I thought maybe it was a string conversion issue, but I’m not sure.
We’re using Client App SDK v2.12.4 and Embeddable Framework v1.8.1. I tried wrapping data.customer.id in a try...catch block, but honestly, I don’t want to just mask the problem. I feel like I’m missing something fundamental about how JSONPath works with Data Actions. Is it something to do with special characters in the digit collected? Maybe the Data Action needs to return a specific format? Or is it something to do with the way we’ve set up the data action itself? It’s just… really frustrating, because it works sometimes.