Url

This class provides methods for looking up the relations between URLs and the content they represent, in both directions.

Methods

get

Fetches content information for a URL.

If a URL cannot be found but there exists a redirect for it, then a Moved response is returned containing the new URL. If neither a URL nor a redirect is found while a) the request was made to the root of a domain and b) this domain is owned by a shop, then a Moved response is returned pointing to the start page of the shop, in the default language of the shop.

Parameters

Parameter Description
url The full URL of a webshop page.
query Which info to return. See Query language (optional)

Example 1

A request for a URL pointing to an Article.

API Console
Url.get("http://demobutik.com/ecommerce/textalk-demo/men/in-hac-habitasse", true)
Response
{
  "article": 12565483,
  "articlegroup": 1347891,
  "language": "en",
  "type": "Article",
  "webshop": 22222
}

Example 2

The example below is a request for an Article that has got a new URL and returns a redirect.

API Console
Url.get("http://demobutik.com/old/article/url")
Response
{
  "type": "Moved",
  "url": "http://demobutik.com/ecommerce/textalk-demo/men/in-hac-habitasse"
}

list

Fetch list of URLs and redirects added to the webshop.

Parameters

Parameter Description
query Which info to return. See Query language.
selection Which urls to list. See List selection.

Filter aliases:

  • domain
  • type
  • webshop

Example 1

API Console
Url.list(true, {"filters": {"/webshop": 22222}, "limit": 2})
Response
[
  {
    "type": "Moved",
    "url": "http://demobutik.com/ecommerce/textalk-demo/men/in-hac-habitasse",
    "previous": "demobutik.com/redirect-to-article"
  },
  {
    "type": "Article",
    "url": "http://demobutik.com/ecommerce/textalk-demo/men/in-hac-habitass",
    "article": 40000,
    "webshop": 1,
    "language": "en"
  }
]

lookup

Looks up a URL by the type and object it represents. The correct Webshop must be set in the context.

Parameters

Parameter Description
type Object type as one of "Article", "Articlegroup", "CustomPage", "StartPage" or "Moved".
object The unique identifier of the object depending on type, e.g. for the type "Article", object is the unique identifier of an Article. Use null for StartPage.
language A language code.
variant Optional. For article pages, this can be the unique identifier of an Articlegroup in which the article should appear. For types other than "Article", variant is not used.

Example

API Console
Url.lookup("Article", 12565483, "en")
Response
"http://demobutik.com/ecommerce/textalk-demo/men/in-hac-habitasse"

redirect

Adds an URL redirect to a different page.

Parameters

Parameter Description
from The URL that will cause the redirect. The domain needs to be one of those assigned to the webshop.
to The URL to redirect to.

Example 1

API Console
Url.redirect("http://demobutik.com/ecommerce/textalk-demo/men/in-hac-habitasse", "http://demobutik.com/ecommerce/textalk-demo/men/another-article")
Response
{}

addRoutes

Add a path that will be recognized as custom route for the specified webshop.

Parameters

Parameter Description
routes A list of objects specifying each new route, each route needs to specify the "path",
"category" and "language" attributes. Each path has to be unique for the webshop
independant of language and the category needs to be a string that doesn't match
"checkout", "cart", "checkout-return-page", "article-search-result" or "my-page".

Example 1

ARG Console
Url.addRoutes([{"path": "/foo/{:bar}", "language": "sv", "category": "foobar"}])
Response
{}

removeRoutes

Remove a custom route added to the webshop.

Parameters

Parameter Description
routes A list of objects specifying routes to be deleted, each route needs to specify the
"category" and "language" attributes.

Example 1

ARG Console
Url.removeRoutes([{"language": "sv", "category": "foobar"}])
Response
{}

listRoutes

List all custom routes added to the webshop.

Parameters

Parameter Description
languages Optional. Limit the listing to only those for the specified languages.

Example 1

ARG Console
Url.listRoutes(["sv", "en"])
Response
[
  {
    "path": "/foo/{:bar}",
    "category": "foobar",
    "language": "sv"
  }
]