I currently have a program that will upload selected files to a specific folder on SharePoint and give access to specific users based on their emails using the SharePoint CSOM API, however, I am unable to generate the links for people outside of my domain.
For example: I get
I am currently retrieving the first link by using the code from here: https://www.c-sharpcorner.com/article/generating-sharing-links-report-and-removing-sharing-links-using-sharepoint-onli/
I have also tried other suggestions I have found on StackExchange such as Manage links for shared files
All examples I have found like the above all result in the incorrect links.
In case it is not clear currently, I am not after an anonymous link or how to create shared links (as I already have this working), I am after the link that would appear here: