<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Programmable Automation | Inability to save when template literal added in Data Hub</title>
    <link>https://community.hubspot.com/t5/Data-Hub/Programmable-Automation-Inability-to-save-when-template-literal/m-p/1044054#M2571</link>
    <description>&lt;P&gt;Hahaha that's awesome. Still a bug, but happy you got it solved!&lt;/P&gt;</description>
    <pubDate>Fri, 20 Sep 2024 21:05:59 GMT</pubDate>
    <dc:creator>Teun</dc:creator>
    <dc:date>2024-09-20T21:05:59Z</dc:date>
    <item>
      <title>Programmable Automation | Inability to save when template literal added</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Programmable-Automation-Inability-to-save-when-template-literal/m-p/1043797#M2566</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":waving_hand:"&gt;👋&lt;/span&gt; Hi everyone,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want to make an API call to OpenAI to categorize a HubSpot contact's job title into 1 of 8 job functions.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For some reason, HubSpot's custom code editor does not allow me to save the code when I add the template literal ${jobTitle} into my code. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If I remove the template literal, it saves. &lt;/SPAN&gt;&lt;SPAN&gt;See error message and red box in the screenshot.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I believe my code is right, but am I missing something trivial?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any help is greatly appreciated.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-09-20 at 8.52.36 AM.png" style="width: 999px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/127399iF83BC7457668A8AD/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-09-20 at 8.52.36 AM.png" alt="Screenshot 2024-09-20 at 8.52.36 AM.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;exports.main = async (event, callback) =&amp;gt; {
    // OpenAI API endpoint and key
    const openaiUrl = 'https://api.openai.com/v1/chat/completions';
    const apiKey = process.env.OPENAI_API_KEY; // Use secret storage in HubSpot for API keys

    // Extract the jobTitle from the contact
    const jobTitle = event.inputFields['jobTitle']; 
    console.log(jobTitle);

    // Prepare the request data for OpenAI
    const data = {
        model: 'gpt-3.5-turbo',  // or 'gpt-4' based on your preference
        messages: [
            {
                role: 'system',
                content: 'You are a helpful assistant.'
            },
            {
                role: 'user',
                content: `A HubSpot contact has the job title, '${jobTitle}' - pick 1 category they fall into based on these options: [Executive, Marketing, Sales, HR/Office/People, Billing, Distributor, Production / Operations, Merch Store].`
            }
        ],
        max_tokens: 10,
        temperature: 0
    };

    try {
        // Send the request to OpenAI using fetch
        const response = await fetch(openaiUrl, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'Authorization': `Bearer ${apiKey}`
            },
            body: JSON.stringify(data)
        });

        // Parse the JSON response correctly
        const responseData = await response.json();  // Define responseData here

        // Get the job function from the parsed response
        const job_function = responseData.choices[0].message.content.trim();

        // Return the job function as the output of the custom action
        callback({
            outputFields: {
                job_function: job_function
            }
        });

    } catch (error) {
        console.error('Error:', error);
        callback({
            outputFields: {
                job_function: 'Error'
            }
        });
    }
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 14:18:40 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Programmable-Automation-Inability-to-save-when-template-literal/m-p/1043797#M2566</guid>
      <dc:creator>JamesonC</dc:creator>
      <dc:date>2024-09-20T14:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: Programmable Automation | Inability to save when template literal added</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Programmable-Automation-Inability-to-save-when-template-literal/m-p/1044018#M2567</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/766045"&gt;@JamesonC&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you try to remove the single quotes around ${jobTitle}?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've used similar code quite a lot in custom code actions, and passing a variable to a string with backticks shouldn't be an issue, so the only thing I can think of is the single quotes wrapping the ${jobTitle} in your prompt.&lt;BR /&gt;If that does solve your issue, you probably want to notify HubSpot support, because that does seem like a bug.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 20:11:32 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Programmable-Automation-Inability-to-save-when-template-literal/m-p/1044018#M2567</guid>
      <dc:creator>Teun</dc:creator>
      <dc:date>2024-09-20T20:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: Programmable Automation | Inability to save when template literal added</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Programmable-Automation-Inability-to-save-when-template-literal/m-p/1044043#M2568</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/101258"&gt;@Teun&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, that didn't work either... I guess I'll move forward with reporting this as a potential bug.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 20:52:31 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Programmable-Automation-Inability-to-save-when-template-literal/m-p/1044043#M2568</guid>
      <dc:creator>JamesonC</dc:creator>
      <dc:date>2024-09-20T20:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: Programmable Automation | Inability to save when template literal added</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Programmable-Automation-Inability-to-save-when-template-literal/m-p/1044046#M2569</link>
      <description>&lt;P&gt;I had a similar issue in the past, could you try renaming `jobTitle` to something else? I couldn't save a code action and thought I was going crazy, but renaming the variable solved it.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 20:55:09 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Programmable-Automation-Inability-to-save-when-template-literal/m-p/1044046#M2569</guid>
      <dc:creator>Teun</dc:creator>
      <dc:date>2024-09-20T20:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: Programmable Automation | Inability to save when template literal added</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Programmable-Automation-Inability-to-save-when-template-literal/m-p/1044050#M2570</link>
      <description>&lt;P&gt;Wow... hahah&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That worked&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/101258"&gt;@Teun&lt;/a&gt;! Never would have thought of that. Thank you for the idea!&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 21:00:46 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Programmable-Automation-Inability-to-save-when-template-literal/m-p/1044050#M2570</guid>
      <dc:creator>JamesonC</dc:creator>
      <dc:date>2024-09-20T21:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: Programmable Automation | Inability to save when template literal added</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Programmable-Automation-Inability-to-save-when-template-literal/m-p/1044054#M2571</link>
      <description>&lt;P&gt;Hahaha that's awesome. Still a bug, but happy you got it solved!&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 21:05:59 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Programmable-Automation-Inability-to-save-when-template-literal/m-p/1044054#M2571</guid>
      <dc:creator>Teun</dc:creator>
      <dc:date>2024-09-20T21:05:59Z</dc:date>
    </item>
  </channel>
</rss>

