Create a contact and attach a document programmatically

I have a custom registration form that users must submit proof of business to open an account.

I can create a contact, add labels, and such, but I would like to be able to attach their proof of business or tax exemption documents to their contact data. When viewing the contact from the dashboard, I can manually add a document. However, I can not figure out how to do it when creating the contact following form submission.

Working in
Dev Mode

What I’m trying to do
Describe the goal or outcome you’re hoping for

What I’ve tried so far
I scoured the documentation and found the Attachments API, which I believe is what I need, but I’m having trouble figuring out how to implement it.

I have been struggling to grasp the syntax of the new documentation.

This tells you how to add a document to your contact. It is very straightforward. It should be the same for a contact you created manually or one that was created as a result of a form submission.

Do i understand it right?

Step-1: A new user is on your registration form.
Step-2: The user do the registration (but incomplete, because proof docs missing due to no automation ???)
Step-3: Then you as admin do proof every user manually by your own?

This is what i read out of your messages…

When viewing the contact from the dashboard, I can manually add a document.

Manually? Really?

But here…

However, I can not figure out how to do it when creating the contact following form submission.
…i hear a cry for automation, not so???

So, i don’t think this will help…


…at least not if the intention was to generate a dynamic registration form with automatic proof-submission.

I agree this will not help if automation is what she wants. I wasn’t sure…Perhaps she can clarify.

Yes, I am trying to automate the process of attaching documents to a contact when they register for the site.

I am pretty sure that it is possible using the Attachments API, however, the documentation looks completely foreign to me. I can’t figure out where to even start.

To make your setup completely automatic you will need the following steps.

1) You will have to code an → UPLOAD-BUTTON ← and connect it to your form-submission.

2) User will fill out all the fields and attach a file (for example pdf-file or similar).

3) The upload then will go to the Wix-Media or Wix-Content-Manager, once the user has completed the form and clicked onto the submission button.

4) Once uploaded the file you get the corresponding file-URL, now you can use that file-url and save it inside of the contact’s extended field.

So when you open the contact, you should see that attachment (URL).

a) ABOUT —> EXTENDED FIELDS…

b) ABOUT —> WIX-MEADIA…

c) ABOUT —> WIX-FORMS…

So now all your users would be able to attach files by their own to their submissions and you could directly check the url inside the extended field (clicking on it or at least copy and paste to get a look onto it). Now you as the OWNER can decide if you want to approve that new contact/member, or not, after reviewing his attached document.

Even this last step could be automated aswell, but this would need a lot of coding. So the last approvement step will still be on you —> you check the attachment and decide what to do → approvement or declinement.

The following links, could also help you —>

  1. How to submit a form with or without files attached

  2. How to upload from BUFFER?

  3. Preview images before upload - #15 by cleytonbsb009

…and you surely will find more informations about your issue, or at least posts which are connected to your issue.

I did that at one point. I tried using the extended fields to attach the documents, but they were not downloadable (I think that was the issue with doing it that way; it’s been a while since I tried that).

I was hoping that someone had experience using the method in this documentation and could share their code to get me started.

That is the only documentation that I’ve found that relates to the Contacts Attachments field.

You are using → Wix-Headless ???

I don’t know what that is so I’m guessing not.

I successfully automated the process of attaching a document to a contact from registration and provided a downloadable link for the document in a triggered email. The trick was using the url returned from getDownloadUrl instead of the url returned from the upload button.


/***********        FRONT END CODE         *************/

import {  getDownloadUrl  }from "backend/media"

let downloadURL

$w.onReady(function () {

	$w("#uploadDoc").onChange(()=>{
		$w("#uploadDoc")
			.uploadFiles()
			.then(async(uploadedFiles) => {

				// For each downloaded file 
				uploadedFiles.forEach(async(uploadedFile) => {
					
					// Get a downloadable url
					downloadURL = await getDownloadUrl(uploadedFile)
					
				});
			})
			.catch((uploadError) => {
				let errCode = uploadError.errorCode; // 7751
				let errDesc = uploadError.errorDescription; // "Error description"
			});
	})

})


/**********    BACKEND MODULE    media.jsw  *******/

import { mediaManager } from "wix-media-backend";

export async function getDownloadUrl(fileUrl){
    const myFileDownloadUrl = await mediaManager.getDownloadUrl(fileUrl);
    return myFileDownloadUrl;
}

You’ve now used it correctly with Wix Media via Velo, without needing to rely on the REST API. :handshake:

To work with the REST API, you’d likely need to use Wix Headless, since that requires authentication through a token along with a client or account ID. That’s why I initially mentioned Wix Headless.

It looks like the information I shared earlier helped point you in the right direction—well done! :tada:

At the end you now know, that there are always more then just one single way to get your solution. :wink:

I just tried that → Wix-Headless ← out to be capable to use the REST-API, which is more complicated then just using Wix-Velo-way.

CONCLUSION: → There is no need to use REST-APIs, if you can do the same with VELO-API.