0

I am sending below payload in Create Customer Rest Api in Magento2 but still getting error.I dont want to turn off recaptcha from admin panel. Is there any way to bypass REcaptcha in magento.

url: {url}/index.php/rest/V1/customers

payload

"customer": {
    "email": "[email protected]",
    "firstname": "John",
    "lastname": "Doe",
    "storeId": 1,
    "websiteId": 1
},
"password": "Demo1234",
"g-recaptcha-response": "03AFcWeA4h9g8CToI6b3NRMEijISsbXgNmTQ2I_QM3ZizdEO2N-Icy1mMpPjjc8ianb6tbWSvq6zCUCygqiL4tLg3caV4Cc6UEvWwETVqAeNR5r7pp-Y8YyBzPKDyBSvK9IFWa_effuqVIHrdd9_RC3Qwij4AHQP96WHcbIqpicd6IYRhMum1QdI5R2cpVf85EYu6-dTJnschVhVtHutYgp5-WOk34GfHZaimQSDFNrIiL6XGzY41zOZWcyNZSRo6g7J2ZNAWwN9uTxrqw_WogfXX2yAWO72Mjw0opts4fEgVA8hGtYyWNTGEEl6oN5ySG4LLuYHO7SrlfwWsdcDdZRP5YJvw5847h7qbTPNo9dc3w2Ibje_PGEZVxkO65zx5jpBYWdifgrZy4wTBvhRR_kDclrTzXueGTnDn3n-gW30o6PJXx1llyX5idXAabuRosyKgGF6wdgPQBNiZo_Jcq2z3U8J_JelyoX5MigdeL4_1e-4AoGkMDJnA1gQMFRPTmVgfM0GHbrjZiHN05ueEnkcNrITPlCK76fk3XTm0mFoNgpqcqJapZa7ru1nea5AgivscMO-zmaQ-XgN1RcgVeCf2ATP7XXnZ3Tr9xuzMr7COheEGCH692OqRzbgsGquX5wqCEzZb6aI9yOtkU56e-TIsNHIsCKjmtURi-MQhf6MDmw0znikhmzo1ce0INvpbcFBoUTHo0rzx4G7KRtAnmFjmPeLBmP5efsjb69ost0F8vexY3qOEN5tgegLaHAUEZNiNYPxBlsdh0"}

Error

{
"message": "ReCaptcha validation failed, please try again"
}

When i turn off recaptcha from admin panel its working fine. But i dont want to turn off recaptcha. Is there any way to bypass this error

thanks in advance.

3
  • Trying to pass a g-recaptcha-response yourself, makes really little sense - those responses are tied to the client the captcha was solved on to begin with, as far as I know. "But i dont want to turn off recaptcha" - what exactly is it turned on for, currently? At which point of using your site, does the user need to solve a captcha? That an API was protected by a captcha, that makes little sense to begin with - APIs are for automated processes triggered by "computers" instead of humans. Commented Mar 22, 2024 at 11:56
  • CBroe Right now captcha is enbaled because it's using in Create Account Form. But I'm implenting user registration modal with rest api so i can register the user through modal also added recaptcha in the modal form and getting the response from recaptcha and sending in api but still not able to bypass Commented Mar 22, 2024 at 12:15
  • i am also facing same issue , i dont know how to resolve it Commented Oct 17, 2024 at 10:30

1 Answer 1

1

Try this

Link: BASE-URL/rest/V1/customers

Body:

{
"customer": {
    "email": "[email protected]",
    "firstname": "abc",
    "lastname": "abc",
    "storeId": 1,
    "websiteId": 1
},
"password": "Password123"
}

My/Module/etc/module.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="My_Module">
        <sequence>
            <module name="Magento_ReCaptchaUi"/>
        </sequence>
    </module>
</config>

My/Module/etc/di.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface">
        <plugin name="captcha_plugin_is_captcha_enabled" type="My\Module\Plugin\IsCaptchaEnabledPlugin" sortOrder="1" disabled="false"/>
    </type>
</config>

My/Module/Plugin/IsCaptchaEnabledPlugin.php

<?php
declare(strict_types=1);
namespace My\Module\Plugin;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\ReCaptchaUi\Model\IsCaptchaEnabled;
use Magento\Framework\HTTP\Header;
use Magento\Framework\HTTP\PhpEnvironment\RemoteAddress;
use Magento\Store\Model\ScopeInterface;

class IsCaptchaEnabledPlugin
{
    private ScopeConfigInterface $scopeConfig;
    private Header $httpHeader;
    private RemoteAddress $remoteAddress;
    private $urlInterface;
    public function __construct(
        ScopeConfigInterface $scopeConfig,
        Header $httpHeader,
        RemoteAddress $remoteAddress,
        \Magento\Framework\UrlInterface $urlInterface
    ) {
        $this->httpHeader = $httpHeader;
        $this->remoteAddress = $remoteAddress;
        $this->scopeConfig = $scopeConfig;
        $this->urlInterface = $urlInterface;
    }
    public function afterIsCaptchaEnabledFor(
        IsCaptchaEnabled $subject,
        bool $result
    ) {
        $api = "rest/V1/customers";
        $current_url = $this->urlInterface->getCurrentUrl();
        if ($api) {
            if (strpos($current_url, $api) !== false) {
                return false; 
            }
        }
        return $result;
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

this is not google solution to by pass the validation , bots my access the api

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.