Skip Navigation

[Resolved] Send again the creed content using webhook to Mailwizz api

This support ticket is created 5 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 7 replies, has 2 voices.

Last updated by Beda 5 years, 5 months ago.

Assisted by: Beda.

Author
Posts
#1315365

Tell us what you are trying to do?
I need to pass the creed content email name surname and a few things to the mailwizz (my mail robot) after the post has created a post (called person)

Is there any documentation that you are following?
https://toolset.com/forums/topic/sending-cred-data-to-third-party-systems/
https://toolset.com/documentation/programmer-reference/cred-api/#cred_submit_complete

Until now i did the hook and it's working...
but i dont get how to write the code that gets the $name $email and ... so on.
to put it in my php code so that i can send it back to the api ?

i would ge it this way ...... $lname = $_GET['lname'];

and send it this way to the api ------
$endpoint = new MailWizzApi_Endpoint_ListSubscribers();
$response = $endpoint->create($listUid, array(
'EMAIL' => $email,
'LNAME' => $lname,
'FNAME' => $fname

a liltle help would be apreciated.
i'm sure it's not dificult but i'm lost in the code
can you help me ?

#1315375

Generally, when an app requires data, what's required is having an API in that App that allows listening to certain input (and eventually then do certain actions).
This is what the Toolset Forms API does.
It allows to listen to certain input, and manipulate it at a given moment, then do a certain action with it, related to what it does (create posts and users) in the range of PHHP possibility.

Hence, the place you look for such an API is the mailwizz app, because it is the one that will manipulate, or else use, the data it reads from whatever object you pass to it.

This is basically the same as I already explained in the ticket you read about:
https://toolset.com/forums/topic/sending-cred-data-to-third-party-systems/

I understand the issue you face now, you don't know how to write the code that gets the $name $email and ... so on, to put it in a Forms API Snippet so that it can be sent it back to the api of mailwizz.

The problem here is, as I try to explain in the previous ticket and above, that the approach to the solution is wrong.
You would have to look out for an API in the plugin that will work with it.

Then you don't need to "send" that data anywhere, you just need to "listen" with the 3rd Party APP to the right endpoints as provided by that API.
If there is no such API in that software it will be very difficult passing data to it with any tool you choose.

See, the Forms API is really nothing else but a set of "moments", taken from the standard life of a post-publication process in WordPress.
You have save_post() in the backend, from WordPress, and Toolset Forms uses the same.
it, however, offers a few moments in that process where you can hook in and add whatever code you want.

That's like you'd add any code you want to the save_post() hook of WordPress
If you can pass that data in the save_post() hook to your third party, it'll be possible in Forms. However, both the save_post and forms API will need to send the data to things provided by the third-party app.

If those endpoints are not there, no code will be able to send any data to it.

What I can definitely help with here, is to "get" the data in a Forms Hook itself, when you submit a Form. You can later do anything you want with it, if PHP's limitations and WordPress limitations allow it.

Usually, you will get data from the form using the $_POST['form_field_name'].
You can get the precise form_field_name from the HTML source of the Form when analysing it in the front end.
hidden link

I suggest to var_dump or error_log(print_r($var_to_dump, true)); the $_POST so to see what you actually have at disposition.

Note, sometimes you will need earlier or later Toolset Forms hooks or instead of $_POST use post object of $post_id, to get Fields and Post data:
https://toolset.com/errata/cred_save_data-does-not-hold-native-post-data-in-post/

From here on, you have the data and can do with it what you want - within the Forms Hook moment you are (cred_save or any other hook) and within WP's and PHP's limitations.
So if at this moment an API hook of a third party can be fired, and needs above data to be populated, you can use the variables populated with the $_POST data or $post_id's object (get_post($post_id))
See: https://developer.wordpress.org/reference/functions/get_post/

Here is an example that gets your_custom_field_slug value and updates the post title with it:
https://pastebin.com/2BTbVbcs

Now, this is the exact same you'd do when updating or firing any 3rd party API with that data, just that instead of wp_update_post() you'd fire your 3rd party's API method at this point.

#1317739

Yehhh it's almost done.
can you tell me what code do i need to put in the action that fires when "cred_save_data" is detected.
So that this code sends the wpcf-personne-email field is sent as (for exemple) EMAIL to the script mybeautyfullapi.php
There à get it with a $email = $_POST['EMAIL'];
It works well with "formidable forms"
And all this work is to get rig of formidable to work only with toolsets tools.
THanks again for helping.
Alexis

#1317745

No, this is exactly what I mean when I say, that the Forms API is a hook, that lets you add your custom code at a certain moment.
We, or Toolset API, however, do not provide the code inside that Hook, this is like when you use WordPress hooks, they also only offer the "hook", nothing else, the code within is specific to each application created, that is why it's called "custom code".

You'd, as explained above, use for example a cred_save_data() or an earlier moment, to grab data either with $_POST or get_post_meta as my example of code I shared shows

Then, "send" it to the app you use, but that's their API, they will have some functions, that you can use, or maybe you can update a post instance they create, I do not know what that plugin does/expects or works with (in code)

You'd as explained, have to ask their support for their API and then use that API to get data to populate their Plugin with.

I can here only assist in the usage of Toolset API, and there is not much more that might explain the usage of it at this point, given the goal is outside that API.

I am not entirely sure what you mean with "It works well with "formidable forms".
If it works with that plugin it's either because they integrated somehow with or, the code you use for that plugin is functional while the one used for Toolset isn't, but the would majorly depend on the code you hooked, which you could share here with me but I could only assist in a consultative manner with it.

Please explain how that works in Formidable pro, so maybe we can do it with Toolset, however, the custom code to talk to the other plugin, is not something either Formidable or Toolset can help you with.

Please let me know the details so maybe I can come up with another example code more tailored to the situation.

#1317751

MMH ok you meen that this code does not make sense..?
> i'm not understanding the whole process (an myabee my english is not so good ?
Thanks anyway

function my_fire_data_action($post_id, $form_data){
// Change your CRED Form "ID" accordingly below

// if ($form_data['id']==611672){

$email = get_post_meta( $post_id, 'wpcf-personne-email', true );
$lname = get_post_meta( $post_id, 'wpcf-personne-nom', true );
$api_url = 'hidden link';

$body = array(
'ID' => $post_id,
'email' => $email,
'name' => $lname ,

);

$request = wp_remote_post( $api_url, array( 'body' => $body ) );

About the formidable form they have an extention that put an action to the form (sign in the wordpress site for exemple) that send data to an API.
They ask for the URL of the API.
and aslo theys ask me to map the data i want to send.
EMAIL > is email
LNAMZ > is last name
... and so on.

#1317781

The code you shared above seems incomplete to me

Please refer to our Documentation, the example I shared and our forum.
Every function in WordPress needs to be fired at some point.
In the Toolset API for forms, we do that with the Forms API.
Then we add_action() this code.

You seem to not add this code anywhere.

Taking your sample, it would look like this in a cred_save_data() hook:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data (there are tons of usage examples in the "More" sections)

//Fire the code on cred_save_data
add_action('cred_save_data', 'my_save_data_action',10,2);

//Our function
function my_save_data_action($post_id, $form_data) {
   //Whatever, this is all custom code
}

Now, I'd tr with something like this - interpreted from your code:

//Fire code
add_action('cred_save_data', 'my_save_data_action',10,2);

function my_save_data_action($post_id, $form_data) {

  if ($form_data['id']==611672){//Change to your form ID

    //with this, you get the post field created by Types "personne-email". Note, if there is no such field no value is given, so please var_dump or error_log(print_r($var_to_dump, true)); as I have already explained, the values you get here, so to be sure they are populated.
    //https://developer.wordpress.org/reference/functions/get_post_meta/
    $email = get_post_meta( $post_id, 'wpcf-personne-email', true ); 
    $lname = get_post_meta( $post_id, 'wpcf-personne-nom', true );
    $api_url = '<em><u>hidden link</u></em>';
    //Above works, you can simply confirm thhis by var_dump the values you get here. If no values there, nothing was saved or something else is wrong. You can only proceed, if the 3 variables show values.

//From here on you are on wp remote post WordPress API ground. It is not Toolset API, just like above is not - however I do not think this code can work, looking at the DOC of it: https://codex.wordpress.org/Function_API/wp_remote_post 
//It seems much more complex than just an array. However, that is completely subject to Custom Code. If it works in a save_post native WordPress action like this, then it will also work here in forms.

    $body = array(
        'ID' => $post_id, //this is the ID of the post you just edited or created. If that is what you need, fine, but note that you cannot force the Post ID of a Post in WordPress ot at least, it's not very good, They should be incrementally unique and WP Manages that just fine- I see no sense in adding the SAME ID of a post to another post
        'email' => $email,//email we get from personne-email (types field that is saved for a post...)
        'name' => $lname , //same here, field value, so if above code gets us the field value, then we are done and expect the next code (wp_remote_post) to work properly with it
    );
  }


$request = wp_remote_post( $api_url, array( 'body' => $body ) );//Please consult the Codex linked above, I do not think the wp_remote_post works like this

}

As you see, the Forms API code will fire your code at a given moment and nothing can influence it to break, unless:
- you miss the data for it
- it is to soon for the custom code to be fired

Does that precise same code work in formidable pro?
I cannot imagine this works because the wp_remote_post() function you use to me seems to be missing parts, as seen on the code codex, so it couldn0t be that it works in Formidable pro.

In any case, this is really custom code.
You can create a fully working wp_remote_post somewhere without Toolset at all.
Then, once it is working, just grab that code and put it in a cred_save_data() populating it with the values you get for example with get_post_meta

Forms will have no influence over the actual code of WordPress core.
I rather think the wp_remote_post is not complete, comparing your code and the codex, however as stated we cannot help with this here, you'd have to contact a contractor from https://toolset.com/contractors/ to receive assistance with that part.

#1317789

THanks so much for your time.
Figuring out what to do !

#1317795

You are welcome, please let me know if anything remains unclear.