Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DT-M3] Create dt-maarifa API to receive contact and interaction data #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

adventureit
Copy link

The Maarifa RS currently uses built-in DT APIs to create contacts and comments. This mostly suits our needs right now, but some options to expand the Maarifa Plugin features could use their own API.

Creating 3 endpoints just for the Maarifa Plugin that the RS will send data to directly and DT can handle some special cases better.

-POST /wp-json/dt-maarifa/v1/contacts
-POST /wp-json/dt-maarifa/v1/contacts/:id
-POST /wp-json/dt-maarifa/v1/contacts/:id/interactions

3 endpoints created.
1st - Create new contact/update if maarifa_data already exists - Ok, if using DT json formating;
2nd - Update based on DT id - Ok, if using DT json formating;
3rd - Create/update interactions - In progress. Create and update are Ok, if using DT json formating, but needs to add some fields.

It also remains to map the DT x Maarifa fields and use it before performing the above actions.
… - Maping Maarifa x DT fields

Creating function mapFieldsToContact to map Maarifa x DT Fields and contemplate differences and exceptions.
Mapping Maarifa x DT fields and correcting adding and updating comments.
Corrections on Mapping Maarifa x DT fields (tags and milestones).
@cairocoder01
Copy link
Collaborator

cairocoder01 commented Oct 2, 2024

@adventureit Nice work getting this started. I tested the first endpoint and found a number of problems, so I didn't test the others yet since they will probably have the same ones. Once the bugs below are fixed, I can test the other 2 endpoints and look at the code in more detail.

Simple Contact

When sending to POST /wp-json/dt-maarifa/v1/contacts

{
    "id": 12345,
    "name": "John Doe",
    "email": "[email protected]",
    "phone": "+1-9995551234",
    "street": "South Pole",
    "country": "antarctica",
    "gender": "male",
    "age": "35-44",
    "notes": "General info about contact"
}

I get the error:

{
    "code": "create_post",
    "message": "'notes' field expected to be an array",
    "data": null
}

When sending to POST /wp-json/dt-maarifa/v1/contacts
with simple data above (without notes property)

I get the error:

{
    "code": "update_multi_select_fields",
    "message": "missing values field on: milestones",
    "data": {
        "status": 400
    }
}

However, it does create a contact and will succeed on the second try.

After the second try, I noticed these bugs:

  1. the contact does not have the street/country values in the Locations or Address fields
  2. the maarifa_data field is set to the id but should be the whole contact json object (this will cause the Maarifa tile on the contact screen to show the id and other info)
  3. the contact should have a source of 'maarifa' added
  4. the age field is not being set

Full

When sending to POST /wp-json/dt-maarifa/v1/contacts

{
    "id": 45235,
    "name": "Jon Doe \/ Bob Johnson",
    "email": "[\"[email protected]\",\"[email protected]\"]",
    "phone": "[\"+44-1234567890\",\"+1-9995551235\"]",
    "phonecode": "+44",
    "skype": "",
    "facebook": "",
    "street": "South Pole",
    "country": "antarctica",
    "ip_city": null,
    "ip_city_id": null,
    "gender": "male",
    "age": "45+",
    "background": "christian",
    "spiritual": "seeker",
    "tags": [{
        "id": 11,
        "name": "\u0623\u062d\u0644\u0627\u0645 \u0631\u0648\u062d\u064a\u0629",
        "alias": "spiritual-dreams"
    }, {
        "id": 19,
        "name": "\u0627\u0628\u0646 \u0627\u0644\u0633\u0644\u0627\u0645",
        "alias": "person-of-peace"
    }],
    "notes": "testest",
    "created": 1602661663,
    "last_updated": 1710502175,
    "last_seen": 1710502175,
    "first_contact": "whatsapp",
    "first_contact_details": null,
    "first_source": "-",
    "ds_user_id": "",
    "external_id": "20",
    "external_url": "https:\/\/maarifa.journey.tools\/demo",
    "location_details": null,
    "milestones": {
        "has bible": true,
        "studying": true,
        "profession": false,
        "can share": false,
        "sharing": false,
        "baptized": false,
        "baptizing": false,
        "in group": false,
        "starting groups": false
    }
}

I am noticing these bugs:

  1. phone numbers are not split
  2. emails are not split
  3. location not set
  4. age not set
  5. Missing source of Maarifa
  6. maarifa_data set to id instead of full object
  7. Notes fails with message about needing to be an array. Removed that property to test the above.

Code Formatting

You might notice that on this pull request, there is a notice that checks failed. If you click into that, you should be able to see that the PHPCS (PHP code sniffer) - which makes sure the code is formatted in a consistent way - is failing. You can run that check locally by using these commands on your command line:

composer install
composer run lint
composer run lintfix

The third one will try to automatically fix whatever it's able to. Mostly it fixes spacing of the code. The second will tell you exactly what other issues there are. Let me know if any of them are hard to understand.

@cairocoder01 cairocoder01 self-assigned this Oct 2, 2024
Fixing bugs:
-maarifa_data field
-age field
-phone numbers are not split
-emails are not split
-age not set
-maarifa_data set to id instead of full object
-Notes fails
-Code Formatting
@adventureit
Copy link
Author

Hi, Jon. Thanks for your review and support.
Bugs fixed, except location (still working on it) and source = maarifa. I do not have Maarifa as an option on my sources list. Should i have it or need do add it somehow?

Thank you.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants