Yelp / yelp-fusion

Yelp Fusion API
https://yelp.com/developers
MIT License
403 stars 394 forks source link

Business search API issue when '&' (ampersand) in the business name #524

Closed jstumpges closed 5 years ago

jstumpges commented 5 years ago

Overview

Description

Aside from the example mentioned in the summary, it looks like any URI reserved characters are not being percent-encoded in any query string param value, but unreserved characters are, which implies that perhaps the wrong URI method is being used to percent-encode the values..

Endpoint

Yelp Fusion business search

Parameters or Sample Request

https://api.yelp.com/v3/businesses/search?term=H&M&latitude=33.14579773&longitude=-117.33180237&location=Carlsbad&locale=en_US&maxresults=3&radius=32000

Response

{
    "businesses": [
        {
            "id": "OOflEjgmh5_rrbvOeJzStA",
            "alias": "miramar-h-and-a-auto-repair-center-i-san-diego-5",
            "name": "Miramar H&A Auto Repair Center I",
            "image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/du_ohOie6nZ2Rgqb5jHRAg/o.jpg",
            "is_closed": false,
            "url": "https://www.yelp.com/biz/miramar-h-and-a-auto-repair-center-i-san-diego-5?adjust_creative=NTwnIvAm3YsUzOkMqZ8ZgA&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=NTwnIvAm3YsUzOkMqZ8ZgA",
            "review_count": 126,
            "categories": [
                {
                    "alias": "autorepair",
                    "title": "Auto Repair"
                },
                {
                    "alias": "transmissionrepair",
                    "title": "Transmission Repair"
                },
                {
                    "alias": "bodyshops",
                    "title": "Body Shops"
                }
            ],
            "rating": 4.5,
            "coordinates": {
                "latitude": 32.8974199,
                "longitude": -117.12284
            },
            "transactions": [],
            "location": {
                "address1": "9585 Black Mtn Rd",
                "address2": "",
                "address3": "",
                "city": "San Diego",
                "zip_code": "92126",
                "country": "US",
                "state": "CA",
                "display_address": [
                    "9585 Black Mtn Rd",
                    "San Diego, CA 92126"
                ]
            },
            "phone": "+18586899969",
            "display_phone": "(858) 689-9969",
            "distance": 33798.37659260786
        },
        ...........
        ...........
        ...........
        ...........
    ],
    "total": 2600,
    "region": {
        "center": {
            "longitude": -117.33180237,
            "latitude": 33.14579773
        }
    }
}
yifanli78 commented 5 years ago

Hi @jstumpges Thank you for raising the question! In general, URL encoding needs to be handled by the caller side. Since URL is used to access all resources on the Internet, it requires a set format to be used for all resources. As part of the RFC 6570 standard, '&' is used for specifying form-style query continuation. Therefore, '&' needs to be URL encoded when it appears in other parts of the URL. For example, for business names with '&', you will need to replace '&' with '%26' in the URL before sending the request to our API sever. You can check out this page to learn more about URL encoding. If you are interested in learning more about URL format, you can take a look at RFC 6570