<?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: Associate a note with a custom object in a workflow custom code action? in Data Hub</title>
    <link>https://community.hubspot.com/t5/Data-Hub/Associate-a-note-with-a-custom-object-in-a-workflow-custom-code/m-p/731958#M1175</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/92056"&gt;@kaious&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for reaching out!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to tag some of our experts -&amp;nbsp;&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/101258"&gt;@Teun&lt;/a&gt;,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/17186"&gt;@Anton&lt;/a&gt;,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/257487"&gt;@LMeert&lt;/a&gt;&amp;nbsp;do you know what's happening here?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have any advice for&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/92056"&gt;@kaious&lt;/a&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;Kristen&lt;/P&gt;</description>
    <pubDate>Fri, 16 Dec 2022 15:11:40 GMT</pubDate>
    <dc:creator>kvlschaefer</dc:creator>
    <dc:date>2022-12-16T15:11:40Z</dc:date>
    <item>
      <title>Associate a note with a custom object in a workflow custom code action?</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Associate-a-note-with-a-custom-object-in-a-workflow-custom-code/m-p/731731#M1174</link>
      <description>&lt;P&gt;Hi, I'm using the below code in a custom action which I have adapted from a HubSpot supplied example to attach a note to a contact.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a note on a custom object instead of a contact, so have updated the following:&lt;BR /&gt;- end point on line 46 changed &lt;STRONG&gt;/contacts/&lt;/STRONG&gt; to the custom object type ID (&lt;/P&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;2-10586829)&lt;BR /&gt;- type in inputs (line 56) changed to&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN&gt;note_to_2-10586829&lt;BR /&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;- updated input to send the ID of a custom object, not contact ID.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I ran this before altering, it ran as expected for the contact.&lt;BR /&gt;&lt;BR /&gt;After updating, it returns no API errors, returns a valid note ID, but fails to attach that note to the custom object in HubSpot (I've updated the input to send the object ID of a custom object of the correct type).&lt;BR /&gt;&lt;BR /&gt;So I'm thinking there must be something wrong with the way I'm addressing the custom object in the association call, however, can't figure out exactly what ...any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;exports.main = async (event, callback) =&amp;gt; {

    /**
     * &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/36718"&gt;@name&lt;/a&gt; getPortalInfo
     * @desc Grab the portal id and various other infos
     * @returns {promise}it returns an axios object
     */
    const getPortalInfo = async () =&amp;gt; {
        const endpoint = `https://api.hubapi.com/integrations/v1/me`;

        return axios.get(endpoint, axiosConfig);
    }
    
    const createNote = (properties) =&amp;gt; {

        const endpoint = `https://api.hubapi.com/crm/v3/objects/notes`;

        return axios.post(endpoint, { "properties": properties }, axiosConfig);
    }


    if (!event.inputFields.hubspot_owner_id) throw new Error(' event.inputFields.hubspot_owner_id is not set, are you sure you added the hubspot_owner_id in the "property to include in code" option ? ');

    if (!event.inputFields.latestNote) throw new Error(' event.inputFields.latestNote is not set, are you sure you added the latestNote in the "property to include in code" option ? ');

    if (event.inputFields.latestNote === "") throw new Error(" event.inputFields.latestNote is empty, we can't create empty notes ");

    const noteCreated = await createNote({
        "hs_timestamp": new Date(),
        "hs_note_body": event.inputFields.notes_next_action,
        "hubspot_owner_id": event.inputFields.hubspot_owner_id
    });

    const { id } = noteCreated.data;

    const associateNoteWithContact = async (noteId, toObjectID) =&amp;gt; {

        const endpoint = "https://api.hubapi.com/crm/v3/associations/notes/2-10586829/batch/create";

        return await axios.post(endpoint, {
            "inputs": [{
                "from": {
                    "id": noteId
                },
                "to": {
                    "id": toObjectID
                },
                "type": "note_to_2-10586829"
            }]
        }, axiosConfig);
    }


    if (!event.inputFields.hs_object_id) throw new Error(' event.inputFields.contactId is not set, are you sure you added the contactId in the "property to include in code" option ? ');

    const res = await associateNoteWithContact(id, event.inputFields.hs_object_id);

    const { status } = res.data;

    console.log(id);

    callback({
        outputFields: {
            id
        }
    });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2022 06:04:30 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Associate-a-note-with-a-custom-object-in-a-workflow-custom-code/m-p/731731#M1174</guid>
      <dc:creator>kaious</dc:creator>
      <dc:date>2022-12-16T06:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: Associate a note with a custom object in a workflow custom code action?</title>
      <link>https://community.hubspot.com/t5/Data-Hub/Associate-a-note-with-a-custom-object-in-a-workflow-custom-code/m-p/731958#M1175</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/92056"&gt;@kaious&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for reaching out!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to tag some of our experts -&amp;nbsp;&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/101258"&gt;@Teun&lt;/a&gt;,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/17186"&gt;@Anton&lt;/a&gt;,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/257487"&gt;@LMeert&lt;/a&gt;&amp;nbsp;do you know what's happening here?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have any advice for&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/92056"&gt;@kaious&lt;/a&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;Kristen&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2022 15:11:40 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Data-Hub/Associate-a-note-with-a-custom-object-in-a-workflow-custom-code/m-p/731958#M1175</guid>
      <dc:creator>kvlschaefer</dc:creator>
      <dc:date>2022-12-16T15:11:40Z</dc:date>
    </item>
  </channel>
</rss>

