Your first action is going to be to figure out what went wrong and what was your role in what went wrong, this is not about blaming for blames sake, it’s about figuring out what you need to do to apologize and to make things right, remember it takes two to make a relationship and two to break a relationship, so be honest with yourself and take your share of the blame.
The bottom line is that to get your ex back, you are going to need an effective top draw apology, the apology must, in effect serve two ends: an explanation of why you are sorry and a further explanation of the plan you are going to implement so that the same wrong behavior never occurs again, get these two planks right and your apology will work for you.
Explaining to your ex about why you are sorry for what has happened, means that you have taken the time to sit and figure out what your ex found so objectionable about your behavior, if you find it difficult to dispassionately figure this out, then you might need to go and talk to a professional about the specifics of your situation, a professional can help you see things from the point of view of your ex and if you want to get your ex back, this could be the key.
What this doesn’t mean is that you become a doormat for your ex and agree with whatever they say and whatever they object to, that is why it is good to have a professional third party look at the situation and give you their thoughts, if they believe your ex has a point about an aspect of your behavior, then they will tell you and they may even go on and work with you to change that behavior.
The second part of your apology, as said, involves explaining to your ex how what happened will never happen again, this is when you present your ex with the plan that you have put in place to ensure no repeat of what happened, when your ex hears about your well thought out plan, as you attempt to get someone back, it will be in your favor, your ex will see that you are serious and sincere in what you are saying, so if you are working with a professional, this is a great indicator to your ex that there is hope for a second chance.
Above all, be honest and sincere and your second chance with your ex will be far more likely.