In Magento 2, it is possible to get a product's URL using the information returned via the API/Repositories?

That is, when grabbing a list of products from the API, the url_key will be returned as part of the custom_attribute array.

  8 => 
    array (size=2)
      'attribute_code' => string 'url_key' (length=7)
      'value' => string 'joust-duffle-bag' (length=16)

However, the actual product URL in the system will not be returned.

Is there a way, using only the API, to get a product's actual URL?

Or am I mistaken, and calls to the ProductRepository API method should include the URL. If so, what should those calls look like?

Or does this question not make sense due to the way Magento 2 handles product URLs? If so, what's "dumb" about this question?

I realize it's possible, using the provided PHP objects, to use a Magento\Catalog\Model\Product\Url object with an instantiated Magento\Catalog\Model\Product object. What I'm looking for is an "API only" way to return a product's URL.

  • Hi Alan - I don't believe we support that feature. what use cases do you need to support so an API call returns the product page's URL?
    – Chuck
    Commented Jan 15, 2016 at 22:51
  • @Chuck Theoretical Use Case: Third Party Email Newsletter Application wants to fetch product information to include in a newsletter, and wants a link to the product page so it can embed an HTML link to the product page. Commented Jan 15, 2016 at 23:01
  • Another use case: some affiliate tracking code requires the product URL.
    – Vinai
    Commented Dec 14, 2016 at 18:44
  • Alan, I very much agree and was told that this feature was in the product backlog. github.com/magento/magento2/issues/10276#issuecomment-316124070 In the meantime, you can use product ID as I showed in my answer. Commented Jul 18, 2017 at 19:24

3 Answers 3


After extensive research and two months of being open, it seems the answer to this question is No. The Magento 2 API can't be used to directly fetch a product URL.


The value url_key (which is returned by the Products API) can be used to build a URL for some products - for example, product 547 in the test dataset has url_key = "zoltan-gym-tee", and you can do


and it works.

You may also use the product ID (returned in the Products API) to build a URL.

For product 541, this would be


For either of these to work, be sure the visibility flag is set correctly for this product in Admin->Products->Catalog. The visibility must include "Catalog."

  • 1
    +1 for useful information (and that's the work around we ended up going with), but this approach isn't without its problems. What if a system has the .html file extensions turned off for URLs, or has rewrite rules that don't use the url_key? Or what happens with parent/child products (configurable/simple, bundle, etc.) when you start building URLs with raw controller actions and IDs. Easy enough to fix on a local level, hard to know what the right thing to do for redistributable code is. Commented Jul 18, 2017 at 21:06
  • @AlanStorm Agreed! That's why I nagged them to fix. (See my comment on your question.) Commented Jul 18, 2017 at 21:13

You can use an api search query as below, to target the url_key by using a combination of searchCriteria and fields https://devdocs.magento.com/guides/v2.4/rest/retrieve-filtered-responses.html

We also use the fields to filter the response and only return the information we need

https://www.domain.com/rest/V1/products? // url
searchCriteria[filter_groups][0][filters][0][field]=sku& // search for field sku
searchCriteria[filter_groups][0][filters][0][condition_type]=neq& // not equal to
searchCriteria[filter_groups][0][filters][0][value]=null& // null (we do this to target all products)
searchCriteria[filter_groups][1][filters][1][field]=type_id& // target the type of product
searchCriteria[filter_groups][1][filters][1][condition_type]=in& // where in
searchCriteria[filter_groups][1][filters][1][value]=configurable,giftcard& // configurable, giftcard (these products are the products you can view in the store)
searchCriteria[filter_groups][2][filters][2][field]=website_id& // we target the website_id to shrink our product scope to a website
searchCriteria[filter_groups][2][filters][2][condition_type]=eq& // website_id equal too
searchCriteria[filter_groups][2][filters][2][value]=1& // website id 
searchCriteria[filter_groups][3][filters][3][field]=status& // we target the status to shrink the product result set even more
searchCriteria[filter_groups][3][filters][3][condition_type]=eq& // equal to
searchCriteria[filter_groups][3][filters][3][value]=1& // enabled
fields=items[sku,type_id,created_at,updated_at,custom_attributes[publish_date,url_key]] // we are only interested in the following fields

An example response looks like

    "items": [
            "sku": "XYZ123",
            "type_id": "configurable",
            "created_at": "2019-05-24 23:48:42",
            "updated_at": "2021-07-30 10:18:29",
            "custom_attributes": {
                "1": {
                    "attribute_code": "url_key",
                    "value": "xyz-123"
                "7": {
                    "attribute_code": "publish_date",
                    "value": "2020-09-29 00:00:00"
            "sku": "ABCDEF",
            "type_id": "configurable",
            "created_at": "2019-05-24 23:52:25",
            "updated_at": "2021-05-28 22:21:35",
            "custom_attributes": {
                "1": {
                    "attribute_code": "url_key",
                    "value": "product-abc-def"

From there you can construct it by hand as example http://www.domain.com/[store_code]/[url_key](.html)

Your Answer

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

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