# Update the segment and create a contact from the script

**URL:** <https://forum.mautic.org/t/update-the-segment-and-create-a-contact-from-the-script/31491>\
**Category:** Product Support\
**Created:** [March 30, 2024, 8:16am UTC](https://forum.mautic.org/t/update-the-segment-and-create-a-contact-from-the-script/31491 "2024-03-30T08:16:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![veeravenkatasai](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/veeravenkatasai/32/14546_2.png) [@veeravenkatasai](https://forum.mautic.org/u/veeravenkatasai)\
**Post date:** [March 30, 2024, 8:16am UTC](https://forum.mautic.org/t/update-the-segment-and-create-a-contact-from-the-script/31491/1 "2024-03-30T08:16:20Z")

</div>

**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:

---

<div class="post-metadata">

**Author:** ![i\_fycode](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/i_fycode/32/13219_2.png) [@i\_fycode](https://forum.mautic.org/u/i_fycode)\
**Post date:** [April 1, 2024, 3:38pm UTC](https://forum.mautic.org/t/update-the-segment-and-create-a-contact-from-the-script/31491/2 "2024-04-01T15:38:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dirk\_s](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/dirk_s/32/748_2.png) [@dirk\_s](https://forum.mautic.org/u/dirk_s)\
**Post date:** [April 1, 2024, 4:24pm UTC](https://forum.mautic.org/t/update-the-segment-and-create-a-contact-from-the-script/31491/3 "2024-04-01T16:24:44Z")

</div>

The Mautic Dev documentation is your friend here:  
[https://developer.mautic.org/#create-contact](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](https://developer.mautic.org/#add-contact-to-a-segment)
