Kevin.a Kevin.a - 1 year ago 93
PHP Question

Check if data exists

I'm working with an API.

With an array I collect data like this:

$org_payload = array(
'name' => $_POST['billing_company'],
'phone' => $_POST['billing_phone'],
'email' => $_POST['billing_email'],
'note' => $_POST['order_comments'],
'relation_type' => array(
'id'=>'relationtype:c1ec3ae77036842d' //provide the relationtypeid, f.e. relationtype:796ce0d318a2f5db515efc18bba82b90
'visiting_address' => array(
'country_code' => 'NL',
'line_1' => $_POST['billing_address_1'],
'postal_code' => $_POST['billing_postcode'],
'locality' => $_POST['billing_city'],
'country' => $_POST['billing_country']

), // can be extented with other address data
'postal_address' => array(
'country_code' => 'NL'
) // can be extented with other address data

At one point i send this data to the program i'm working with. I achieve this with this code:

$organization = $SimplicateApi->makeApiCall('POST','/crm/organization',json_encode($org_payload));

I gather this data from a form on my website. This data gets posted in the program.

I am trying to achieve that when data gathered from my form matches existing data in the program then don't add it. I would like a hint in the right direction for this, been looking on the internet without any luck.

Answer Source

What I would suggest is to have one extra call to the API.

Like you said in the comments - the company name and the phone number is unique. If there is some call to get a user by those values and check what you got from the form, would be enough.

If they are unique - send them, if not - show to the user or whatever you want to do here.

No need to keep one more database on your system as well.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download