API GET Request
-
Hi there
I’ve built my own plugin. Where you can fill in a form, when fields are filled in you can click on submit, and all form fields will be sent to an api post request.
Only one problem, the email has to be unique. The API allowes you to use an email multiple times. To prevent that I thought of making an API GET request that searches through all customers with the JUST filled in email.$email = wp_remote_get('https://www.sportivity.com/sportivity-api/Customers/ByType/type?email='.$result['inputs']['email'].'&mem=T', [ 'headers' => [ "Content-Type" => "application/json", "Accept" => "application/json", "X-API-TOKEN" => $token, "Connection" => "keep-alive", ], ]); $email = json_decode($email['body'], true); wp_send_json($email); if(count($email['CustomerResources']) > 0){ $result['errors']['email']['nl_msg'] = 'Email al in gebruik!'; wp_send_json($result); }
The wp_send_json($email) returns an object like this, when I fill in an existing email:
{ "CustomerResources": [ { "CustomerId": 12889043, "FirstName": "dfdf", "MiddleName": "dfdf", "LastName": "dfdfdf", "Email": "[email protected]", "Address": "Wooshstreet", "HouseNumber": "12", "Zipcode": "2312SX", "City": "The Hague", "BirthDate": "29/10/2019", "Language": "Nederlands", "CustomerHasActiveMemberships": false, "TermsAccepted": false, "CompanyLocationId": 0, "CustomerLocations": [ { "LocationId": 13653, "LocationName": "Sandbox Impressie", "Status": "Prospect" } ] }, { "CustomerId": 12889218, "FirstName": "dfdfdf", "MiddleName": "dfdfdf", "LastName": "dfdfdf", "Email": "[email protected]", "Address": "blabblastreet", "HouseNumber": "12", "Zipcode": "2312LP", "City": "Amsterdam", "BirthDate": "29/11/2019", "Language": "Nederlands", "CustomerHasActiveMemberships": false, "TermsAccepted": false, "CompanyLocationId": 0, "CustomerLocations": [ { "LocationId": 13653, "LocationName": "Sandbox Impressie", "Status": "Prospect" } ] }, { "CustomerId": 12889206, "FirstName": "dffddf", "MiddleName": "dfdfdfdf", "LastName": "dfdfdf", "Email": "[email protected]", "Address": "Teststreet", "HouseNumber": "12", "Zipcode": "2312LP", "City": "Leiden", "BirthDate": "28/10/2019", "Language": "Nederlands", "CustomerHasActiveMemberships": false, "TermsAccepted": false, "CompanyLocationId": 0, "CustomerLocations": [ { "LocationId": 13653, "LocationName": "Sandbox Impressie", "Status": "Prospect" } ] }, ], "error": { "HttpStatusCode": 200 } }
How do I loop through those items in PHP and make sure when there are 1 or more customers with the same email, that it will prevent the Customer Post call from activating?
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘API GET Request’ is closed to new replies.