Optional URL parts

Is there a way to add optional URL parts
if I have a URL for the API like this API/v1/Document/89324892348923489 where the last part is in this case a unique identifier. In other cases it could be a Type of something
API/v1/Create/Invoice in this case an invoice

You can utilize the path variable {{optional_path}}

Alternatively, utilizing path parameters could be an optimal solution. Here is a link with more information about it: https://apidog.com/help/api-documentation/api-design#path-parameters

Can I make them optional ?

No, defined path parameters can not be optional since they are specified as part of a URL. However, if you prefer, you can utilize an empty string.