<?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: How to set a file field via the forms API in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/How-to-set-a-file-field-via-the-forms-API/m-p/248752#M21545</link>
    <description>&lt;P&gt;Hi &lt;A class="mention" href="https://community.hubspot.com/u/calicoderco"&gt;@calicoderco&lt;/A&gt;, File upload properties are text properties, and they’re designed to store the URL of a file that’s uploaded to some storage platform. The property itself cannot store an actual file, so if you’re using an upload property in a custom form, you’d need to upload the file separately, and then store a URL that could be used to access that file in the actual form field being sent to HubSpot. A call to the Files API could work, but it'd need to be done server side as doing so client side would expose your API key.&lt;/P&gt;</description>
    <pubDate>Tue, 22 Jan 2019 17:17:12 GMT</pubDate>
    <dc:creator>cbarley</dc:creator>
    <dc:date>2019-01-22T17:17:12Z</dc:date>
    <item>
      <title>How to set a file field via the forms API</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-to-set-a-file-field-via-the-forms-API/m-p/248751#M21544</link>
      <description>&lt;P&gt;Thanks to some help on this community I was able to get my regular form fields to set through the v3 API. I'm wondering, though, for one field which is a file field (credit_report), how do I set that? I need to accept a credit report PDF. I'm a lending company doing sales through hubspot and I need to accept a PDF from people whoa re signing up. Do I post the entire file binary data in the request body? Like this..?&lt;/P&gt;
&lt;P&gt;{&lt;BR /&gt;
"fields": [&lt;BR /&gt;
{"name": "email", "value": &lt;A&gt;"bj@gmail.com&lt;/A&gt;"},&lt;BR /&gt;
{"name": "firstname", "value": "Bob"},&lt;BR /&gt;
{"name": "lastname", "value": "James"},&lt;BR /&gt;
{"name": "phone", "value": "445233311"},&lt;BR /&gt;
{"name": "address", "value": "My address"},&lt;BR /&gt;
{"name": "state", "value": "Delaware"},&lt;BR /&gt;
{"name": "city", "value": "Warm Springs"},&lt;BR /&gt;
{"name": "country", "value": "USA"},&lt;BR /&gt;
{"name": "dob", "value": "02261986"},&lt;BR /&gt;
{"name": "company", "value": "MyCompany"},&lt;BR /&gt;
{"name": "credit_report", "value": ""}&lt;BR /&gt;
],&lt;BR /&gt;
"legalConsentOptions": {&lt;BR /&gt;
"legitimateInterest": {&lt;BR /&gt;
"value": true,&lt;BR /&gt;
"subscriptionTypeId": 999,&lt;BR /&gt;
"legalBasis": "CUSTOMER",&lt;BR /&gt;
"text": "Legitimate interest consent text"&lt;BR /&gt;
}&lt;BR /&gt;
}&lt;BR /&gt;
}&lt;/P&gt;
&lt;P&gt;I have noticed that if I fill out the form through Hubspot's provided form link, the resulting contact in hubspot shows the credit report as a link to a file which has a url like this: &lt;A href="https://cdn2.hubspot.net/hubfs/" rel="nofollow noopener"&gt;https://cdn2.hubspot.net/hubfs/&lt;/A&gt;/form-uploads/. That's exactly what I want, except I want it to happen when I fill out the form via the forms API from my Javascript client code. Good news is all the other fields work, I just don't know how to do the file field.&lt;/P&gt;
&lt;P&gt;Do I need to use a separate API for this? Such as the Files API. &lt;A href="https://developers.hubspot.com/docs/methods/files/post_files...I" rel="nofollow noopener"&gt;https://developers.hubspot.com/docs/methods/files/post_files...I&lt;/A&gt; see that there are different APIs that might be relevant but I don't know how to connect them together..like how will the uploaded file get referenced in the contact data set by the forms API?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 23:56:20 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-to-set-a-file-field-via-the-forms-API/m-p/248751#M21544</guid>
      <dc:creator>calicoderco</dc:creator>
      <dc:date>2019-01-17T23:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a file field via the forms API</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-to-set-a-file-field-via-the-forms-API/m-p/248752#M21545</link>
      <description>&lt;P&gt;Hi &lt;A class="mention" href="https://community.hubspot.com/u/calicoderco"&gt;@calicoderco&lt;/A&gt;, File upload properties are text properties, and they’re designed to store the URL of a file that’s uploaded to some storage platform. The property itself cannot store an actual file, so if you’re using an upload property in a custom form, you’d need to upload the file separately, and then store a URL that could be used to access that file in the actual form field being sent to HubSpot. A call to the Files API could work, but it'd need to be done server side as doing so client side would expose your API key.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jan 2019 17:17:12 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-to-set-a-file-field-via-the-forms-API/m-p/248752#M21545</guid>
      <dc:creator>cbarley</dc:creator>
      <dc:date>2019-01-22T17:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a file field via the forms API</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-to-set-a-file-field-via-the-forms-API/m-p/317415#M30407</link>
      <description>&lt;P&gt;Using the&amp;nbsp; submit form v2 endpoint, you can just append a file object to the formData before submitting it, like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;var file = new File( [signatureBlob], fileName, { type: 'image/jpg' } );
formData.append('signature', file);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This uploads the file and stores the url in the relevant property which looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://api.hubspot.com/form-integrations/v1/uploaded-files/signed-url-redirect/00000000000?portalId=XXXXXX&amp;amp;sign=xxxxxxxxxxxxxxxxxxxxxxxxxxx%3D&amp;amp;conversionId=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx&amp;amp;filename=9768ee88-d5cf-4c52-af98-a15f02596a41.jpg" target="_blank" rel="noopener"&gt;https://api.hubspot.com/form-integrations/v1/uploaded-files/signed-url-redirect/00000000000?portalId=XXXXXX&amp;amp;sign=xxxxxxxxxxxxxxxxxxxxxxxxxxx%3D&amp;amp;conversionId=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx&amp;amp;filename=9768ee88-d5cf-4c52-af98-a15f02596a41.jpg&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We use this to capture a signature in a landing page, and store it in hubspot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately this doesn't work with the v3 endpoint as it only accepts application/json.&amp;nbsp; Would be great if we could just pass in a base64 encoded file as an form value, and have Hubspot handle it the same way the v2 endpoint does.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 03:44:03 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-to-set-a-file-field-via-the-forms-API/m-p/317415#M30407</guid>
      <dc:creator>chrispower</dc:creator>
      <dc:date>2020-02-07T03:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a file field via the forms API</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-to-set-a-file-field-via-the-forms-API/m-p/340769#M33300</link>
      <description>&lt;P&gt;Thanks I was also adding a signature to a form and your method helped, though I needed to add a file name in the append or in my case set.&lt;/P&gt;&lt;P&gt;I was using the standard hubspot form in a module so I left the default form in and just stopped it from submitting and submitted using ajax instead:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;window.addEventListener('message', event =&amp;gt; {
	if(event.data.type === 'hsFormCallback' &amp;amp;&amp;amp; event.data.eventName === 'onFormReady') {
		//Form has been created
		var $form = $('.hs_signature').closest('form'); //SELECT YOUR FORM - I'M SELECTING FORMS WITH WITH THE SIGNATURE FIELD
		$('input[type="submit"]',$form).on('click',function(e){
			e.preventDefault();
			var formData = new FormData($form[0]);
			formData.set('signature', file, 'signature');

			//Submit data manually
			var portalID = $form.data('portal-id');
			var formID = $form.data('form-id');
			var url = 'https://forms.hubspot.com/uploads/form/v2/' + portalID + '/' + formID;
			$.ajax({
				url: url,
				data: formData,
				processData: false,
				contentType: false,
				type: 'POST',
				mode: 'no-cors'
			});
		});
	}
});&lt;/PRE&gt;&lt;P&gt;And I used the idea here for my e signature just use jquery to append the required fields and save it as a blob to a file instead of the Data URL&amp;nbsp;&lt;A href="https://codepen.io/dus7/pen/qGQbVP" target="_blank"&gt;https://codepen.io/dus7/pen/qGQbVP&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 May 2020 08:31:51 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-to-set-a-file-field-via-the-forms-API/m-p/340769#M33300</guid>
      <dc:creator>matt_scott</dc:creator>
      <dc:date>2020-05-21T08:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a file field via the forms API</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-to-set-a-file-field-via-the-forms-API/m-p/1028232#M75909</link>
      <description>&lt;P&gt;How do I send more than one file?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;OBS: I'm using this endpoint&amp;nbsp;&lt;A href="https://api.hsforms.com/submissions/v3/integration/submit/:portalId/:formGuid" target="_blank" rel="nofollow noopener noreferrer"&gt;https://api.hsforms.com/submissions/v3/integration/submit/:portalId/:formGuid&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 15:54:57 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-to-set-a-file-field-via-the-forms-API/m-p/1028232#M75909</guid>
      <dc:creator>adriano-azos</dc:creator>
      <dc:date>2024-08-16T15:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a file field via the forms API</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-to-set-a-file-field-via-the-forms-API/m-p/1028846#M75935</link>
      <description>&lt;P&gt;If it's in different fields should be easy&lt;/P&gt;
&lt;PRE&gt;var filedata1 = new File( [file1], fileName1, { type: 'image/jpg' } );&lt;BR /&gt;var filedata2 = new File( [file2], fileName2, { type: 'image/jpg' } );
formData.append('field1',filedata1);&lt;BR /&gt;formData.append('field2',filedata2);&lt;/PRE&gt;
&lt;P&gt;Or is it to the same field?&lt;BR /&gt;Maybe you can just submit the form twice but the second time with the different file. Hubspot introduced multiple files for one property fairly recently&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2024 08:32:52 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-to-set-a-file-field-via-the-forms-API/m-p/1028846#M75935</guid>
      <dc:creator>matt_scott</dc:creator>
      <dc:date>2024-08-19T08:32:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a file field via the forms API</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-to-set-a-file-field-via-the-forms-API/m-p/1028979#M75943</link>
      <description>&lt;P&gt;Hubspot doesn't support multiple files on the API.&lt;BR /&gt;I had an idea that I embed form and hid it.&lt;/P&gt;&lt;P&gt;So, before sending the form, I transfer all files into the form.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2024 13:40:29 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-to-set-a-file-field-via-the-forms-API/m-p/1028979#M75943</guid>
      <dc:creator>adriano-azos</dc:creator>
      <dc:date>2024-08-19T13:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a file field via the forms API</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-to-set-a-file-field-via-the-forms-API/m-p/1064257#M77886</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;Thanks for shre the code here I applied the code but still my signature not added into property after submission I need a solution would you please help me ?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;script src="https://cdn.jsdelivr.net/npm/signature_pad@4.0.0/dist/signature_pad.umd.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script&amp;gt;
document.addEventListener("DOMContentLoaded", function () {
// Initialize Signature Pad
const canvas = document.getElementById('signature-pad');
const signaturePad = new SignaturePad(canvas);

// Function to clear the signature pad
document.getElementById('clear-signature').addEventListener('click', function () {
signaturePad.clear();
console.log("Signature pad cleared.");
});

// Custom form submission handler
document.getElementById('submitForm').addEventListener('click', async function (e) {
console.log("Submit button clicked");

// Check if signature pad is empty
if (signaturePad.isEmpty()) {
alert("Please provide a signature.");
console.log("Signature pad is empty");
return;
}

// Collect form data
const formData = {
fields: [
{ name: "practitioner_name", value: document.getElementById('practitioner_name').value },
{ name: "phone", value: document.getElementById('phone').value },
{ name: "practice_name", value: document.getElementById('practice_name').value },
{ name: "email", value: document.getElementById('email').value },
{ name: "address", value: document.getElementById('address').value },
{ name: "dob", value: document.getElementById('dob').value },
{ name: "signature", "test" }
],
context: {
pageUri: window.location.href,
pageName: document.title
},
legalConsentOptions: { consent: { consentToProcess: true, text: "I consent to have my data processed." } }
};

// Log formData for debugging
console.log("Form Data:", formData);

try {
const response = await fetch("https://api.hsforms.com/submissions/v3/integration/submit/46793903/1dda8ffa-fda1-44f5-8502-cf9daa39c63e", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(formData)
});

if (response.ok) {
console.log("Form submitted successfully.");
document.getElementById('patientForm').style.display = 'none';
document.getElementById('successMessage').style.display = 'block';
} else {
const errorData = await response.json();
console.error("Error submitting form:", errorData);
alert("There was an issue submitting the form.");
}
} catch (error) {
console.error("Submission error:", error);
alert("An error occurred while submitting the form.");
}
});
});
&amp;lt;/script&amp;gt;&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 03 Nov 2024 06:45:34 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-to-set-a-file-field-via-the-forms-API/m-p/1064257#M77886</guid>
      <dc:creator>iBusinessFormul</dc:creator>
      <dc:date>2024-11-03T06:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a file field via the forms API</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-to-set-a-file-field-via-the-forms-API/m-p/1064481#M77909</link>
      <description>&lt;P&gt;looks like after your formdata you need to add the file from your signature plugin&lt;/P&gt;
&lt;PRE class=""&gt;const signatureBlob = await (await fetch(signaturePad.toDataURL())).blob();&lt;/PRE&gt;
&lt;PRE class=""&gt;const file = new File( [signatureBlob], 'signature', { type: 'image/png' } );&lt;/PRE&gt;
&lt;PRE&gt;formData.set('signature', file, 'signature');&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Nov 2024 11:06:33 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-to-set-a-file-field-via-the-forms-API/m-p/1064481#M77909</guid>
      <dc:creator>matt_scott</dc:creator>
      <dc:date>2024-11-04T11:06:33Z</dc:date>
    </item>
  </channel>
</rss>

