Any way to send a signal to put the new lead in a segment so that Campaign can begin...auto

Your software
My Mautic version is:Ver 3.3
My PHP version is: 7.3
My Database type and version is: Mysql

Your problem
My problem is: I want to send a lead by Basic Api and include a signal just like the Api form does to tell the system via api to place that lead in a segment so that when the next cron runs it will run that lead in a campaign that is hooked to that segment.
Is there any field that i can include in the API lead coming in to tell the system to set the segment. Works great on the Mauti form when you set it up you can tell it to set the segment when the lead comes in… but not sure if or how I would send that selection via the API.

any thoughts or ideas would be appreciated.

These errors are showing in the log: None

Steps I have tried to fix the problem: Mostly just search google and the comments on Mautic.

Hi @tommytx123 ,

That should be fairly simple: Mautic Developer Documentation “ADD CONTACT TO A SEGMENT”
→ Is that what you have in mind?

If you want to do this for a brand new lead, you will have to

  • either do it in two steps
  • or indirectly by adding some custom field (with a segment filter on that field)

Best,
Ekke


Ekke Guembel

Mautic Open Source Project, Team Lead "Community"
Mail: ekke.guembel@mautic.org
Profile & Social Media: Leuchtfeuer.com/ekke
Mautic Podcast: mauticast.de (DE) / mauticast.com (EN)

Thanks for the response Ekke… I have the code from that very reference.

<?php

//...
$response = $segmentApi->addContact($segmentId, $contactId);
if (!isset($response['success'])) {
    // handle error
}

Says to simply take the existing segment ID and the contact ID and add them to the variables then push the button in the magic non existing box and bingo done…

That is not the problem: We have no ideas how to get thru the confusing getting TOKENS and making all that work…
But my problem and hundreds (maybe thousands) of others on here is that no matter how many times we go thru the SIMPLE steps of building the code before this… (the secret php code that makes the Authorization… and then use php to drive any of the simple commands like create contact… get a contact… etc… and there lies the problem…
From reading thousands of requests for help it looks like less than 1 in 10 will get it to work… it horrendous to read the hundreds maybe thousands of requests for help that go by the way side… many try to help but if you keep reading you will find that less the 1 or 2 in a hundred get it to work… and apparently they just drift off into the dark and never come back with hey it works… so from that i have to assume they never got it to work or if they did they are not about to share it…I have reviewed more than 1,000 help requests on this very subject and NO WHERE can you find a step by step here is the code that works… even the formal step by step starts off showing you how do set up the non basic and lo and behold a few steps later right in the middle of explaining how to make OUTH2 work… they switch to the details of how to make the basic work… (with use this if the auth is too hard for you)…
Really confusing when you just stop and start teaching something else… It would be so valuable if someone would go thru the entire process and make a you tube or put it in the Mautic Library… I don’t mean this general details, I am talking about an actual live process from your puter… starting with step 1 thur end… everybody talks in general terms and nothing specific…I Know each puter is different but seeing something that works in step by step. And then if we follow the steps and it does not work then we now know enought to ask a specific question and others on here may be able to add the missing point. Like for example does some of the authorization show up in the url that we need to pull out… heck it says save the token… I have tried it 100 times and I have never seen a variable come out … is the token going to show up in the url or where?
For example getting the token… appears to me that we need to be getting stuff from the URL as it runs… like the codes attached to the URL… but no one says where to look for any of that…
So the goal for someone to become a HERO right here would be to do a basic for start to end… then an oath` and oath2… start to finish explaining every step one at at time… and no mixing… with stuff like but in basic case you do that…

So when i say i want to send a signal to the API to place a contact into a specific segment… its a lot more than grabbing those 5 lines of code… I do not understand how to set all the php up to drive that code to make it work… and i have been writing php code a long time… but if someone could work up the code anyone could do it…its not that big… but if you do not understand it you cannot write the code.
If you did it live say one by one… of the three and drug it out you would get tons of questions showing you just how much interest there is…Trust me MOST who have tried it gave up…

Then once we know how to use the php to get the basic and OATH running maybe you could add a few of the examples lke “create new contact”, “get a contact” and or like the one I need “add a contact to a segment” after working with a few live examples like that we should all then be able to rip the api apart running any order we desire… and making many more happy Mautic members.

I just re-read this let me explain exactly what i want to do… and its all in one step. anyone in real estate needs this and i am sure once I understand how to set up the basic driver for the API … and then just be able to plunk the api commands in that driver as needed…
Here is how it works end to end…

  1. In the initial setup I setup and regular old segment manually… then I manually build my campaign… and the ideas is to have every New lead be dumped into the segment so that the next campaign run maybe in 15 min will pick this guy up and run his process in the campaign like for example assigning him to his owner by looking at the URL he brings with him… based on the URL i can see what Website he came from so I know who owns that site… so the campaign can easily check his arrival url and assign him to the correct owner… course the campaign does lots more but this is one thing it does for all new leads.
    Now if i could use the regular Mautic forms it can auto put him into the segment… I just set that action from the Mautic form drop down… but I cannot use the Mautic Form…

So what i do then is dump the contact into the DB and instantly on arrival i need to send the api a command to instantly add that contact to the new lead segment… and all is well…
Unless you have a better idea.

So i believe i can achieve this on my own if i can understand the Mautic API once and for all.
and I am sure you will have a ton of API users if we can make this API user friendly…and i think it is user friendly once we know how it works…

Joeyk and Adam Clark have recently been the most helpful but there is much more we need to know you can see what they have to say here:

https://forum.mautic.org/t/is-anyone-willing-to-share-a-template-to-allow-me-to-communicate-with-the-mautic-api-for-100/19473

That thread is me wanting to learn the API so bad i am willing to pay for it… but its hard to pay as my projects are all hobbies and bring in Zero dollars… but i would love to become and expert at the API…

A suggestion - you can create a bash script to run your commands sequentially, so you don’t have to wait so long. Also: what do you have against basic auth? Super simple. I think I even gave you the code.
Come to the Mautic Helpdesk Meetup today, and explain what you want to achieve, and we figure it out.

It is a non-recorded event, we share some news, chat and fix issues.

Yes i have your basic script when you were helping Adam get going… but it did not work for him until have added to your script especially the part where you had to tie the user and pass together and use base 64 to encode them… Once he did that and added a few more lines it began to work for him.(the basic) and he gave me a copy of your modfied script and it would randomly work but not all the time…
But i saw your video on speed up… i don’t have that need… but sure would love to find out how we tie the basic code down to run with all the API snippets… for example right now I need the hookup to send a signal to theAPI that will tell the new contact to jump into my segment for new leads… I see no way to run anything on basic but the talk with the db… have you tried to run any non contacts to see if that works… BElow is the code to set the contact to the segment… All you do is send the contact ID and the segment ID and you are on a roll… below is the code for that and should run on Basic but has not done so for me…
Thanks again for your help… will look into going to the Meetup Today…Thanks…

<?php

//.
$response = $segmentApi->addContact($segmentId, $contactId);
if (!isset($response['success'])) {
    // handle error
}

Wish we could get a group together that makes up like a video and or Manual blowing all the confusion out of the API… many more would join in on Mautic I am sure… we are all missing out on a ton of fun not knowing the Api well… I have worked with many api and this one is the hardest to get your arms around.
Ekke is just above on this thread or the other one and seems to think this is a simple project to handle the using API to connect a lead to a segment… wish he could come on the Meetup and explain or answer all my questions… Thanks for your help…
Its only a 3 line command for the segment/contact so cant be that hard…

OK i got all signed up for the envent … today my time is 12:00 in Virginia…
Thanks Joeyk… you have been very helpful since i got into Mautic…