0

I have no experience with Magento. I was asigned the task to validate a coupon code via magento rest api. I've tried to use /V1/coupons/search GET method. My request url is:

 https://example.com/index.php/rest/V1/coupons/search/?searchCriteria[filterGroups][0][filters][0][field]=code&searchCriteria[filterGroups][0][filters][0][value]=12345ABC&searchCriteria[filter_groups][0][filters][0][condition_type]=eq

However, my java based server receives a 500 status response.

I've also tried to make a curl request like this:

curl -X GET --header "Authorization: Bearer some-token-string"

https://example.com/index.php/rest/V1/coupons/search?searchCriteria[filterGroups][0][filters][0][field]=code&searchCriteria[filterGroups][0][filters][0][value]=1234ABC&searchCriteria[filter_groups][0][filters][0][condition_type]=eq"

However my console responds:

curl: (3) [globbing] error: bad range specification after pos 92

Any help would be much appreciated. Thanks in advance!

2
  • Hi @alex-g, what version of magento are you using?
    – diazwatson
    Aug 24, 2017 at 13:01
  • 2.1.2 . Sorry, should have included it in the post.
    – Alex G.
    Aug 24, 2017 at 13:03

2 Answers 2

0

Try adding the --globoff argument to your curl command. Curl's globbing feature is misinterpreting the braces in Magento's query syntax as a request for curl to make multiple requests based on a range.

E.g.

curl -X GET --globoff --header "Authorization: Bearer some-token-string" https://example.com/index.php/rest/V1/coupons/search?searchCriteria[filterGroups][0][filters][0][field]=code&searchCriteria[filterGroups][0][filters][0][value]=1234ABC&searchCriteria[filter_groups][0][filters][0][condition_type]=eq"

Documentation for the feature is available here:

https://ec.haxx.se/cmdline-globbing.html

0

In Magento 2x: vendor/magento/module-sales-rule/etc/webapi.xml

Check all coupon related APi End Point

<!-- Coupon CRUD -->
    <route url="/V1/coupons/:couponId" method="GET">
        <service class="Magento\SalesRule\Api\CouponRepositoryInterface" method="getById"/>
        <resources>
            <resource ref="Magento_SalesRule::quote"/>
        </resources>
    </route>
    <route url="/V1/coupons/search" method="GET">
        <service class="Magento\SalesRule\Api\CouponRepositoryInterface" method="getList"/>
        <resources>
            <resource ref="Magento_SalesRule::quote"/>
        </resources>
    </route>
    <route url="/V1/coupons" method="POST">
        <service class="Magento\SalesRule\Api\CouponRepositoryInterface" method="save"/>
        <resources>
            <resource ref="Magento_SalesRule::quote"/>
        </resources>
    </route>
    <route url="/V1/coupons/:couponId" method="PUT">
        <service class="Magento\SalesRule\Api\CouponRepositoryInterface" method="save"/>
        <resources>
            <resource ref="Magento_SalesRule::quote"/>
        </resources>
    </route>
    <route url="/V1/coupons/:couponId" method="DELETE">
        <service class="Magento\SalesRule\Api\CouponRepositoryInterface" method="deleteById"/>
        <resources>
            <resource ref="Magento_SalesRule::quote"/>
        </resources>
    </route>

    <!-- Coupon Management -->
    <route url="/V1/coupons/generate" method="POST">
        <service class="Magento\SalesRule\Api\CouponManagementInterface" method="generate"/>
        <resources>
            <resource ref="Magento_SalesRule::quote"/>
        </resources>
    </route>
    <route url="/V1/coupons/deleteByIds" method="POST">
        <service class="Magento\SalesRule\Api\CouponManagementInterface" method="deleteByIds"/>
        <resources>
            <resource ref="Magento_SalesRule::quote"/>
        </resources>
    </route>
    <route url="/V1/coupons/deleteByCodes" method="POST">
        <service class="Magento\SalesRule\Api\CouponManagementInterface" method="deleteByCodes"/>
        <resources>
            <resource ref="Magento_SalesRule::quote"/>
        </resources>
    </route>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.