Set Email subscriptsion status using velo?

Question:
How to set subscriptsion status of a contact using velo?

Product:
Velo for my Studio site

What are you trying to achieve:
I’d like to set the subscription to a mailing list status using Velo APIs. I believe this was possible in the past (using the “subscriptionStatus”) but this parameter does not exist anymore.
I regularly import new contacts from .json File. For those i got consent, i would Like to Set the subscription Status .
Otherweise I have to do it manually for each contact in the Dashboard.

What have you already tried:
I have tried Out several Things, but Not a solution

Additional information:
Perhaps there is a Work around? I would like to avoid to do it manually for each contact in the Dashboard

Edited: Upon further investigation this field is read only and ther eis no API currently available to update that value. I am asking about this internally to see if anythign is to be released.

subscription-status

Dear @amandam , thanks for your reply.
I have tried to work with this (making use of the extendedFields items), but failed
It seems that this option of subscriptionStatus has “disappeared” form the API when using "createContact() (as I think it was available in the past- but maybe I am wrong here). However, I have to say that I am quite confused by having spotted 2 APIs for {contacts} in both wix-crm.v2 (you are referring to) and wix-crm-backend (I have recently worked with and tried to set the subscription status). I have used the latter one as my code is a backend script, so I’ve assumed this was the logic approach…

Do you know which one to be used for the different purpose?
Do you think it make a difference when creating a “dashboard page” instead?

Acccording to the API reference doc, the method parameter in which “extendedFields” was listed is not “info” (anymore), but “contactInfo”. Here, the extendedFields are listed as a direct child of contactInfo. However, I could not find and havn’t managed to address the emailSubscription item.

Any suggestions are welcome :slight_smile: !
Adrian

Hi Adrian - I updated my comment but icymi…

that field is read only and there is no API exposed to update the subscription status (apologies for the confusion, I responded too quickly before)

I am askign internally if anything is perhaps coming soon I can speak to and will report back.

thanks, this would be great. I do appreciate.
(Also, I suppose no chance to have a workaround using dashboard page etc today?; since this works with the same APIs? [sorry if this is a stupid question…]

Asking about workarounds now. For your json import - how are you doing this? Via velo?

The easiest solution is to import via the business manager which gives you an option to mark a contact as subscribed on import.

Still waiting on more information regarding abilities via velo - but hopefully that is an option in the meantime for your flow

Yeah, using velo, also here a bit of “workarounds”, as it is essentially a “3-step” approach, with some “manual work” in-between…

Step0: outside Wix, I have created a python sktipt that converts my Excel file (that contains the (new) contact data) into a .json file format

Step1: I import the .json dataset into a CMS collection. In fact, doing this, I have 2 options (either … or / both options are independent from each other):

Option A: I have an input textbox in which I copy & paste the json format dataset from the clipboard. I use the JSON.parse(#texbox).value and pull the data into the CMS using wixData.insert(…)

OptionB: I (manually) upload the json file when I am in the media manager … So, the file then does exist in my site files area. In the media pool, I copy the file URL (I retrieve this information from the file info → URL → “copy URL”; this is the “public” URL with “https://…”).
I then paste the URL link into a text input field on my page. Then, in Velo I fetch the data (from the fileURL) using fetch(fileURL) using 'wix-fetch" API and pull the data into the CMS relevant CMS fields (using wix.Data.insert(…) function using wix-data module.

OptionB is somehow my preferred way - however, I haven’t found a way to retrieve the “public” file URL through Velo. I’d like to work with an upload file button and straight retrieve the “public” URL once the file is uploaded. However, I didn’t manage to get the public file URL link (https://…). I was just able to retrieve other information of the file such as the “download URL” using “getFileInfo()” (or getDownloadUrl()) using the MediaManager option of the ‘wix-media-backend’ API.
→ any hints how to get the public URL via Velo is welcome!

Step2:
Then, the 2nd step is to “copy” / transfer CMS records into the contact database using the contacts.create.Contact(…) function from ‘wix-crm-backend’ API. (In this process, I check if the contatcs mentioned in the CMS already exists to ensure that only new contacts are imported / created. This all works very well, even the custom extended fields and labels are correctly set for the new contacts in the contact database - except of setting the subscriptionstatus :slight_smile:

Ok, I hope this does not sound too confusing. Overall, I am quite happy. Two things I’d like to improve:

  • more automatic import process of the .json file (without going the the media pool to get the file URL) and
  • to set the subscription status during the createContact process.

I hope this answers your questions. Otherwise, please let me know.
If you are interested, I am happy to send you more details or the codes from my steps I have mentioned herein.

Regards
Adrian

I have just read your latest reply.
What do you mean with “business manager”? (not clear what it is)
Would this somehow work together with the “process” I have today (my 2 // 3-step approach I mentioned in my previous reply)?

I’m not sure why the media manager and second collection is involved.

If you are creating a python export anyway, why not output a csv instead and import it directly through the dashboard(business manager) Wix Contacts: Importing Your Contacts into Your Contact List | Help Center | Wix.com

Your other option since you have an application oursitde wix potentially is to use the REST api - this is more complex.

Whether or not someone is subscribed is not handled via contacts (it’s shown there). Marketing consent is what handles this status. There is a REST API for updating this but not Velo Update Marketing Consent | REST

As far as a velo API, it seems there is something in the works but not release date right now that I can share so I would plan wihtout it for now

Indeed, your proposed process using the dashboard (business mgr) is more straightforward, that I haven’t condsidered this way so far…
The reason I have been using the media manager is simply to get hold of the file (“public”) URL link, see the screenshot attached.
I haven’t found a way to get this URL via Velo code (do you know how to get this? I am still interested though)

I get the FiledownloadURLs and other file description info, but to the https://… URL

Have a nice day and greeting from Hamburg, Ge
Adrian

What are you trying to do? The url you can get back from a file that was uploaded, would be a url to then download the file (the https url). So i’m not sure the difference between the two URLs.

docs for reference https://dev.wix.com/docs/velo/api-reference/wix-media-v2/files/generate-file-download-url

if what you are looking for is the wix url of the file, perhaps use this https://dev.wix.com/docs/velo/api-reference/wix-media-v2/files/get-file-descriptor
which has url in the return object you can check out to see if it’s waht you mean

Hello amandam,
first, many thanks for your “patience” with me :slight_smile

On the URL:
I have tried using the FiledownloadURL but it is a different one and does not work (see below why I need the correct URL).
The URL I get from the mediamanager (through the “copy link” shown in the screenshot", this (string) is starting with (in my example): "
https://aa6ad2d7-0dda-43c9-9f66-640357f30bd6.usrfiles.com/ugd/xxxxxxx.json

whereas the FileDownloadURL starts with "https://download-files.wixmp.com/media/xxxxxxx`

Also, the URL mentioned in the “get-file-descriptor” seems again another URL (I believe I have checked this one as well, but have deleted the code recently…)

Why do I need this URL at all: in the process step to pull the .json data into the CMS, I use the fetch(fileURL) function (from wix-fetch API) - and this requires specified resource from the network using HTTPS,
see the documentation here.
At least, I got my velo script working using that URL.

On your proposed method, straight going through the dashboard / business manager and importing .csv file:
I just checked out this one.
There are two pain points I could not get around:

  1. there is no way to import specified labels (labels that I have already in the csv dataset). At the very last step in the import workflow, one can indeed (optionally) prompt label(s) - however, this then applies to all imported & updated contacts. [whereas I have different labels for different imported contacts). What indeed works well is to import custom fields data
  2. contacts that already exists are updated. This update even applies to the subscription status (so, I tick-box the email subscription status on for the import). It means that existing contacts that may have set the subscription status to “unsubscribed” is updated to “subscribed”. Ok, one may argue that this is a pure academic use case, as I only import contacts that have given consens to it anyway… Im my velo code, I first check if the contact already exists and do skip - only new conatcts will be created

Adrian

I don’t know any velo way to get that specific url, however, since you are uploading manually anyway I would still bypass the media manager altogether and do everything in code if it were me. Another path for consideration…

put your json files into a backend js file, example:
json-code

Insert into your collection via a backend web module (please note this example is very simplified and you will need to make adjustments to deal with multiple items and more complex objects)

insert-to-db

PLease also remember to modify your code and collection permissions to reflect the highest level of security needed since you are dealing with user data/PII

I was “off” yesterday, sorry for my late response.
Yes, this is another route, thanks.
Finally, for the time being, i guess i will stick to the other option that is to “copy & paste” the json File into the Input Text Box and pull the Data from there. This process is mainly Velo driven.

Thanks again, amandam, for your support over the recent days,
Adrian

1 Like

Hi @amandam, I’m trying to achieve the same thing: I want to give my members the opportunity to switch emails back on using a Velo script. Is there a solution on the horizon? If not, what would a user need to do to switch emailSubscriptions.subscriptionStatus back to “SUBSCRIBED”. I would assume that members can do this on the email settings page in their member area, but this seems to be not the case. Can you help? Thanks so much!