• Resolved argosantifex

    (@argosantifex)


    I hope you don’t mind me reaching out but I could do with some help and i’m not an expert with PHP or JSON. I am trying to integrate CF7 with Flodesk and while I have been able to set this up with Zapier I think it would be great to see if I can figure out how to integrate with Flodesk.

    I have been testing in postman and have been able to get around certain areas but the bit I am stuck on is how to prevent certain fields from being sent to Flodesk. I’ve searched the forums and I can see references to Github examples but I don’t understand what they’re doing to be able to prevent my field “msg-notes” from being included in my JSON array.

    I am following the Flodesk guidance to add the email address, first name and last name onto the subscriber list. The flodesk JSON structure is the following:

    {
    "id": "string",
    "status": "active",
    "email": "string",
    "source": "manual",
    "first_name": "string",
    "last_name": "string",
    "segments": [
    {
    "id": "string",
    "name": "string"
    }
    ],
    "custom_fields": {
    "property1": "string",
    "property2": "string"
    },
    "optin_ip": "string",
    "optin_timestamp": "2019-08-24T14:15:22Z",
    "created_at": "2019-08-24T14:15:22Z"
    }

    what i’ve renamed all my fields so they match but i’m hoping that if i can find away to not send the ‘tel_number’ field and ‘msg_notes’ fields then my array will work?

    Any help would be really beneficial

Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Author Mário Valney

    (@mariovalney)

    Hi! How are you?

    (I’m writing back from my phone, so I’m sorry for poor formatting…)

    About renaming fields, you can add a alias for every field as explained in Readme (plugin’s homepage).

    About not sending a field, I’m afraid it’s not possible right now without some code. I would be happy to provide a snippet when I get my notebook back but it’s really necessary? I’ve never integrated with Flodesk but, in general, it’s not a problem to have more fields been sent.

    Thread Starter argosantifex

    (@argosantifex)

    Hi Mario,

    Apologies for the delay, I ended up using Zapier in the interim while I had some more time to investigate this. I have been playing around in postman to work on variables I need and I think I have everything now.

    The only thing I wanted to check is to be able to add a user to a specific email segment I have to use the URL – /subscribers/{id_or_email}/segments; is it possible to feed the email address from the form and feed it as a variable into the Webhook URL field?

    Thanks

    Plugin Author Mário Valney

    (@mariovalney)

    Hi!

    By now it’s not possible to have placeholders in URL (added this as a feature request).

    But you can filter it. For example:

    <?php
    
    add_filter( 'ctz_hook_url', 'argosantifex_ctz_hook_url', 20, 2 );
    function argosantifex_ctz_hook_url( $hook_url, $data ) {
        $replace = null;
        if ( isset( $data['id'] ) ) {
            $replace = sanitize_text_field( $data['id'] );
        }
    
        if ( ! $replace && ! empty( $data['email'] ) ) {
            $replace = sanitize_text_field( $data['email'] );
        }
    
        if ( is_null( $replace ) ) {
            return $hook_url;
        }
    
        return str_replace( '{id_or_email}', urlencode( $replace ), $hook_url );
    }
    Thread Starter argosantifex

    (@argosantifex)

    Hi Mario,

    Thank you for your reply. I don’t seem to be able to get it to work. When I add the URL to Webhooks it strips out the { } brackets so I’ve amended the code provided to id_or_email and no luck.

    It creates the user using first webhook but the second url the one with (id_or_email) doesn’t work. Any ideas? Would be good to natively implement but if not I have managed to leverage Power Automate to do what I need.

    Thread Starter argosantifex

    (@argosantifex)

    I think I may have found the issue, the segments_id value which is used to place the user into a Segment has to be sent in Array not a string therefore it needs to be in this value

    ?“segment_ids”: [“segment_id_here”]

    Is there a quick way to do this? I will take a look in the forums to see if I can figure it out.

    Plugin Author Mário Valney

    (@mariovalney)

    Plugin Author Mário Valney

    (@mariovalney)

    Hi. How are you?

    In new version 3.0.0 you can use URL placeholders.

    https://www.ads-software.com/support/topic/use-webhook-url-placeholders/

    Thread Starter argosantifex

    (@argosantifex)

    Hi Mario,

    Thank you for the update! I’m sure many will benefit from it. With regards to my final issue – sending the Segment ID as an Array. I was thinking of using another solution as I didn’t understand the example you gave – unfortunately i’m not very good with PHP.

    I was thinking this one – https://www.ads-software.com/support/topic/radio-button-and-checkboxes-empty-in-zapier/

    Would you be able to help me with what I need to add? In my postman example, the ‘segments_ids’ field has to be sent like this within the array:

    { “segment_ids”: [“segement_id_number”] }

    It’s strange that it’s not a string field but I have contacted Flodesk’s dev team and I am awaiting a reply. Using Microsoft Flow works but would be good to sort natively via the WP plugin.

    Plugin Author Mário Valney

    (@mariovalney)

    Please check:

    https://www.ads-software.com/support/topic/change-data-before-send

    Let me know if you need more help.

    Thread Starter argosantifex

    (@argosantifex)

    Sorry to keep coming back to you Mario but still no success. I’ve created a new snippet and used the following code:

    add_filter( 'ctz_get_data_from_contact_form', 'flodesk_ctz_get_data_from_contact_form' );
    
    function flodesk_ctz_get_data_from_contact_form( $data ) {
        // EDIT YOUR DATA
         $data['segment_ids'] = array('a1b2c3d4e5f6');
        return $data;
    }
    

    and my CF7 array shows as follows:

    {
        "first_name": "??????",
        "last_name": "??????",
        "tel_number": "??????",
        "email": "??????",
        "TrainingLocation": "??????",
        "msg-notes": "??????",
        "optin_ip": "??????",
        "segment_ids": "??????"
    }

    The user get’s added to Flodesk but doesn’t get added to any segment.

    Thread Starter argosantifex

    (@argosantifex)

    Okay using webhook.site I’ve managed to figure it out so I can send the Segment ID how I need to and verified it using Postman however the code still doesn’t work with the plugin using the new 3.0 update provided.

    When I set my URL to:

    https://api.flodesk.com/v1/subscribers/[email]/segments

    The user isn’t added to the segement, but if I do

    https://api.flodesk.com/v1/subscribers/[email protected]/segments
    

    and fill in my CF7 form, the user is added to the segment. So, the new issue seems to be that its not picking up the variable? I’ve checked my form and my email field is configured as [email].

    Plugin Author Mário Valney

    (@mariovalney)

    And my CF7 array shows as follows:

    The example in settings ignores code customization.

    When I set my URL to:

    https://api.flodesk.com/v1/subscribers/[email]/segments

    The user isn’t added to the segement, but if I do

    https://api.flodesk.com/v1/subscribers/[email protected]/segments

    I was able to confirm the plugin is working.

    Debuging the hook url it’s requesting https://api.flodesk.com/v1/subscribers/teste%40gmail.com/segments because the parameter is url encoded.

    I guessed Flodesk is not allowing URL encoded and found this:

    https://community.make.com/t/flodesk-integration-help-needed/16396/4

    A partner asked, so it’s nice to check:

    • This subscriber is already set up on Flodesk? To add to a segment, they must already have been created using the subscriber module.
    • And their email address is exactly as the one you are passing?
    • You’ll need to add the Subscriber. However, you may be able add them to Segments in the same module.

    But… If the problem is the encoded value, you can change it:

    add_filter( 'ctz_hook_url_placeholder', 'flodesk_ctz_hook_url_placeholder', 10, 4 );
    
    function flodesk_ctz_hook_url_placeholder( $encoded_value, $placeholder, $key, $data ) {
        if ( $key === 'email' ) {
            return $data[ $key ]; // Ignoring encoded value
        }
    
        return $encoded_value;
    }
    Plugin Author Mário Valney

    (@mariovalney)

    I was able to create a example without code change:

    This will send the request to:

    https://api.flodesk.com/v1/subscribers

    With this body:

    {
      "first_name": "Name",
      "last_name": "Surname",
      "email": "[email protected]",
      "segment_ids": [
        "segment_id_1",
        "segment_id_2"
      ]
    }

    Which I guess is enough to create a user and add to segment.

    • You can add more fields.
    • You can hide “segment_ids” checkboxes with CSS and/or add more segments (check the “default” param to make they already checked).
    Thread Starter argosantifex

    (@argosantifex)

    Hi,

    So when I tested using my Microsoft Flow routine, i added the two Webhook requests one after the other so User Create then User Add fo segment and that works.

    Is there anyway we can get over the URL encoded option. Support still hasn’t come back to me yet.

    Plugin Author Mário Valney

    (@mariovalney)

    I was editing the answer. Please check it again.

    I just added the code to filter the encoded value.

    May you provided the URL of form?

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Integrate with Flodesk’ is closed to new replies.