MBANDAKA, Democratic Republic of Congo — The sting began, as so many things do these days, on social media.Daniel Stiles, a self-styled ape-trafficking detective in Kenya, had been scouring Instagram, Facebook and WhatsApp for weeks, looking for pictures of gorillas, chimps or orangutans. He was hoping to chip away at an illicit global trade that has captured or killed tens of thousands of apes and pushed some endangered species to the brink of extinction."The way they do business," he said of ape traffickers, "makes the Mafia look like amateurs."After hundreds of searches, Stiles found an Instagram account offering dozens of rare animals for sale, including baby chimpanzees and orangutans dressed in children’s clothes. He sent an email to an address on the account — "looking for young otans" (the industry standard slang for orangutans) — and several days later received a reply."2 babies, 7.5k each. Special introductory price."The trafficker identified himself only as Tom and said he was based in Southeast Asia. Stiles knew what Tom was hoping for: to sell the infant orangutans to a private collector or unscrupulous zoo, where they are often beaten or drugged into submission and used for entertainment like mindlessly banging on drums or boxing one another. Such ape shows are a growing business in Southeast Asia, despite international regulations that prohibit trafficking in endangered apes.Several weeks later, after a few more rounds of text messages with Tom to firm up the details, Stiles decided to fly to Bangkok."I was way out on a limb," Stiles admitted later. But he was eager to bring down Tom, who indicated that he could find orangutans and chimps with only a few days’ notice, the mark of a major dealer.‘Endgame conservation’Ape trafficking is a little-known corner of the illicit wildlife trade, a global criminal enterprise that hauls in billions of dollars. But unlike the thriving business in elephant ivory, rhino horns, tiger bone wine or pangolin scales, ape smuggling involves live animals — some of the most endangered, intelligent and sensitive animals on Earth.Stiles, 72, grew intrigued by apes decades ago as a graduate student in anthropology. Since then, he has plunged deeper and deeper into the ape world, becoming the lead author of "Stolen Apes," a report published by the United Nations in 2013 that was considered one of the first comprehensive attempts to document the underground ape trade. He and the other researchers estimated the smuggling had claimed more than 22,000 apes — either trafficked or killed.Malnourished and terrified apes have been seized across the world, in undercover busts or at border checkpoints, in countries as varied as France, Nepal, Thailand, the Democratic Republic of Congo and Kuwait. Two years ago, at Cairo’s international airport, Egyptian authorities discovered a baby chimp curled up into a ball and stashed in a piece of hand luggage. Just this summer, authorities in Cameroon stopped a smuggler at a roadblock who was trying to move 100 pounds of pangolin scales and a tiny chimp, not even a month old, hidden in a plastic sack.But for every successful bust, wildlife specialists say, five to 10 other animals slip through. And for every smuggled ape, several more may have been killed in the process. Most species of apes are social and live in large groups, and poachers often wipe out entire families to get their hands on a single infant, which is far easier to smuggle."Transporting an adult chimp is like transporting a crate of dynamite," said Doug Cress, who until recently was the head of the Great Apes Survival Partnership, a U.N. program to help great apes. "The adults are extremely aggressive and dangerous. That’s why everyone wants a baby."Wildlife researchers say that a secret ape pipeline runs from the lush forests of central Africa and Southeast Asia, through loosely policed ports in the developing world, terminating in wealthy homes and unscrupulous zoos thousands of miles away. The pipeline, documents show, is lubricated by corrupt officials (several have been arrested for falsifying export permits) and run by transnational criminal gangs that have recently drawn the attention of Interpol, the international law enforcement network.Apes are big business — a gorilla baby can cost as much as $250,000 — but who exactly is buying these animals is often as opaque as the traffickers’ identity. Many times, researchers say, they can only begin to track where the apes have ended up by stumbling across the Facebook posts and YouTube videos of rich pet collectors."This is sick," Stiles said as he pulled up a picture of a small chimpanzee wearing lipstick. "You got this poor animal, without its mother, without any other members of its own species, totally bewildered and terrorized, all for human amusement."Wildlife officials said that a handful of Western businessmen had also been arrested. But the majority of recent busts, they said, have been in Africa or Southeast Asia, usually of low-level traffickers or poorly paid underlings, not the bosses who control underground exports and travel abroad to make deals.For years, wildlife officials suspected that a mysterious American known simply as "Joe" was running a large trafficking ring out of Thailand, one of the world hubs for smuggled apes. According to "Tom," the trafficker Stiles discovered, "Joe" had recently retired.And it’s not as if smuggling is the only threat apes face. The world’s hunger for biofuels and palm oil — a cheap food product used in things like lipstick, instant noodles and Oreos — is leveling tropical rainforests and turning them into farms.According to the Arcus Foundation, a nonprofit group that studies apes, Indonesia and Malaysia have tripled their palm oil production in the past 15 years, wiping out the habitats of thousands of orangutans. In Africa, it’s the same, with new rubber plantations, new roads and new farms cutting deeply into gorilla areas. One species, the Cross River gorilla, is now so endangered that scientists think there are only 200 to 300 left."In living memory, there were millions of apes," said Ian Redmond, a well-known primatologist. "Now, there’s just a few hundred thousand and falling.""What we’re looking at," he said, "is endgame conservation."The stingFor years, Stiles has performed undercover research on wildlife trafficking across Africa, but recently his work has taken him off the continent. A big, freckled, gregarious man, he favors wearing baggy shorts and wrinkled safari shirts. He has also invented several false online identities, with web pages that depict him as an active buyer of rare animals.Many illegal wildlife transactions start online, specifically through Instagram or Whats App. Stiles has made several trips to the United Arab Emirates, which he considers a new hub for the illegal online wildlife business. Dealers in the Middle East have posted many pictures of apes for sale, sometimes advertising them as friendly pets for children.Disturbing stories are often behind those pictures. Many chimps have been drugged with muscle relaxers or alcohol to make them easier to handle. Some are trained to smoke cigarettes and guzzle beer. Orangutans are gentler than chimps, but still, they are not always gentle, and investigators say zoo trainers sometimes beat them with lead pipes wrapped in rolled-up newspapers to force them to perform tricks. Several years ago, the Indonesian police rescued a female orangutan who had been shaved and was being used as a prostitute at a brothel."Even if we can rescue them, it’s very difficult reintroducing them to the wild," said Cress, the former head of the U.N. Great Apes program. "They’re all goofed up. They need serious rehab. The ones who have been given alcohol, their hands shake. They have the same withdrawal symptoms we do."International wildlife regulations prohibit the trade of endangered apes for commercial purposes. While zoos and other educational institutions are allowed to acquire apes, they need permits showing, among other things, that the apes were bred in captivity, not captured in the wild. (All great ape species are endangered; most gibbons species are as well.)It’s relatively easy to falsify permits, though, and wildlife investigators have tracked illegally sold apes to Iraq, China, Dubai and Bangkok’s Safari World zoo, where orangutans have been trained to wear boxing gloves and spar with each other to howls of laughter.Safari World was outed more than 10 years ago for using orangutans that had been smuggled from Indonesian jungles. Dozens of animals were seized from the park and flown home, where the wife of Indonesia’s president welcomed them.To arrange his orangutan sting, Stiles checked into the Landmark hotel in Bangkok. From a quiet room overlooking clogged arteries of traffic, he began sending the wildlife trafficker Tom messages on WhatsApp.Stiles knew it was dangerous to flirt with a known smuggler. So he brought his investigation to Freeland, a nonprofit group that combats wildlife and human trafficking from a large office in central Bangkok. Freeland works in secrecy, with undercover agents based in a sealed room that other employees are not allowed to enter. It also works closely with the Thai police services, including one cheerful undercover officer who goes by the name Inspector X.Over the next few days, with Inspector X and other agents lurking in his high-rise hotel room, Stiles exchanged more WhatsApp messages with Tom, trying to arrange a meet-up. A couple of times, they even talked on the phone. Tom’s real identity remained a mystery. He had a Malaysian or Indonesian accent, spoke English fluently and was never at a loss for words."Oh man, you’re going to have some fun," Tom said about the orangutan babies. "Getting ready for some sleepless nights?"In late December, the day of the meet-up, Inspector X and the other Thai agents staked out the appointed location — a supermarket parking lot in central Bangkok. A taxi pulled up.Inspector X and the agents pounced, arresting the driver and discovering two baby orangutans in the back seat, clutching each other. They appeared scared but healthy, and have since been sent to a Thai wildlife sanctuary. But Tom was nowhere to be found.Stiles was overjoyed that the orangutans were rescued, but he was frustrated, too. "We got to get to the dealers," he said.Since the sting, he has been back on Instagram, looking for more apes. And more Toms.