-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: master
Are you sure you want to change the base?
Conversation
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).
@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 ContactWhen sending to
I get the error:
When sending to I get the error:
However, it does create a contact and will succeed on the second try. After the second try, I noticed these bugs:
FullWhen sending to
I am noticing these bugs:
Code FormattingYou 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:
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. |
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
Adding source = maarifa
Adding source = maarifa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adventureit This is working much better now! Nicely done! Adding a contact seems to work great and updating contacts also seems to work well. I wasn't able to add an interaction/comment, but I'm guessing you haven't worked much on that part yet.
I left a few code comments of some things that can be cleaned and a few bugs.
if ( !empty( $contact_map['tags'] ) ) | ||
{ | ||
|
||
$int_count0 = 0; | ||
|
||
foreach ( $contact_map['tags'] as $key => $value ) { | ||
|
||
$fields_map['tags']['values'][$int_count0]['value'] = $contact_map['tags'][$key]['alias']; | ||
|
||
$int_count0++; | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, but there's two things that could clean it up:
- I don't think you need the int_count0 variable. You can just assign to
$fields_map['tags']['values'][] = [ 'value' => $value['alias']
. That[]
means to append a new item to the array. - In that code above, you'll see that I used
$value
instead of$contact_map['tags'][$key]
since it should be the same thing from how you wrote the foreach statement. You get the key and the value, so you can just directly use the value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this suggestion hasn't been changed yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something happened in my last commit and I lost the changes. I redid tit and just made a new commit.
|
||
if ( !empty( $contact_map['milestones'] ) ) { | ||
|
||
$int_count = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above about not needing the int_count. You can just write []
to append a new item to an array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this suggestion hasn't been changed yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something happened in my last commit and I lost the changes. I redid tit and just made a new commit.
Fixing bugs in location (country), interactions, update (returning post), and adding comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there. I just noticed a bug that if you don't send a milestones property in the API body when doing an update, you get an activity message in the DT UI that says "0 added to Faith Milestones"
if ( !empty( $contact_map['tags'] ) ) | ||
{ | ||
|
||
$int_count0 = 0; | ||
|
||
foreach ( $contact_map['tags'] as $key => $value ) { | ||
|
||
$fields_map['tags']['values'][$int_count0]['value'] = $contact_map['tags'][$key]['alias']; | ||
|
||
$int_count0++; | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this suggestion hasn't been changed yet.
|
||
if ( !empty( $contact_map['milestones'] ) ) { | ||
|
||
$int_count = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this suggestion hasn't been changed yet.
} | ||
else //No milestones | ||
{ | ||
$fields_map['milestones']['values'][1]['value'] = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the intention with this code? I noticed that if I didn't send the milestones
property in the API request, the activity comment in DT said "0 added to Faith Milestones".
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