How to check for URL conflicts without creating a entity?

Hi how do I from code perform a URL check to check that a url is not in use / get an alternative url suggestion if it is in use? (I am dynamically creating pages and categorys)

Litium version: 7

I think you can use UrlHelper for that cause.

Any updates/examples to this?
I would like to check if a category already exists with the URL I’m trying to create dynamically with CategoryService.

Inject ISuggetionService and then use Suggest method.

Tried that but gives me the following error:
“Localization[sv-SE].Url: ‘The URL is occupied by a sibling category.’.”

Seems like it only suggests an url, not checking if there’s already an existing category with that suggestion.

It has to give you a non existing url otherwise it might be a bug.

ISuggetionService is not validating that the url-segment is in use, it is suggesting an sanitized url-segment. To be able to validate if the url-segment can be used also other parameters need to be included like if the url is for a page, category, base product or variant and if it is a page or category it also need to know the parent object.

If you only want to do a validation before saving you can inject the ValidationService and use the validate method on that to get an answer if the entity have any invalid data, it is this method that the create/update methods are using.