Update the segment and create a contact from the script

Your software
My Mautic version is: 4.4.7
My PHP version is: 8.0.30
My Database type and version is: pdo_mysql and 8.0.36

Your problem
My problem is: I have a PHP script where it fetches the contacts from the third party API , now whenever it runs it should create a contact or update an existing contact in the segment. Can anyone please help me on this process.

These errors are showing in the log:

Steps I have tried to fix the problem:

I can’t find any error log here and the steps you have taken.

The Mautic Dev documentation is your friend here:
https://developer.mautic.org/#create-contact

  1. First enable access (Basic Auth) in Mautic.
  2. Add a user for the API with required access rights.
  3. 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