The Mautic Dev documentation is your friend here:
https://developer.mautic.org/#create-contact
- First enable access (Basic Auth) in Mautic.
- Add a user for the API with required access rights.
- Implement the calls: You need to check first, if contact already exists, if not add a new one.
Not sure what you mean related to the assignment of the contact to a segment - that would be the way to go: Mautic Developer Documentation