{"id":14988880,"date":"2021-10-20T14:04:39","date_gmt":"2021-10-20T14:04:39","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/api-get-request\/"},"modified":"2021-10-20T14:04:39","modified_gmt":"2021-10-20T14:04:39","slug":"api-get-request","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/api-get-request\/","title":{"rendered":"API GET Request"},"content":{"rendered":"<p>Hi there<br \/>\nI&#8217;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.<br \/>\nOnly 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. <\/p>\n<pre><code>$email = wp_remote_get(&#039;https:\/\/www.sportivity.com\/sportivity-api\/Customers\/ByType\/type?email=&#039;.$result[&#039;inputs&#039;][&#039;email&#039;].&#039;&amp;mem=T&#039;, [\n\t\t\t\t&#039;headers&#039; =&gt; [\n\t\t\t\t\t&quot;Content-Type&quot; =&gt; &quot;application\/json&quot;,\n\t\t\t\t\t&quot;Accept&quot; =&gt; &quot;application\/json&quot;,\n\t\t\t\t\t&quot;X-API-TOKEN&quot; =&gt; $token,\n\t\t\t\t\t&quot;Connection&quot; =&gt; &quot;keep-alive&quot;,\n\t\t\t\t],\n\t\t\t]);\n\t\t\t\n\t\t\t$email = json_decode($email[&#039;body&#039;], true);\n\t\t\twp_send_json($email);\n\t\t\tif(count($email[&#039;CustomerResources&#039;]) &gt; 0){\n\t\t\t\t$result[&#039;errors&#039;][&#039;email&#039;][&#039;nl_msg&#039;] = &#039;Email al in gebruik!&#039;;\n\t\t\t\twp_send_json($result);\n\t\t\t}<\/code><\/pre>\n<p>The wp_send_json($email) returns an object like this, when I fill in an existing email:<\/p>\n<pre><code>{\n    &quot;CustomerResources&quot;: [\n        {\n            &quot;CustomerId&quot;: 12889043,\n            &quot;FirstName&quot;: &quot;dfdf&quot;,\n            &quot;MiddleName&quot;: &quot;dfdf&quot;,\n            &quot;LastName&quot;: &quot;dfdfdf&quot;,\n            &quot;Email&quot;: &quot;jan@live.nl&quot;,\n            &quot;Address&quot;: &quot;Wooshstreet&quot;,\n            &quot;HouseNumber&quot;: &quot;12&quot;,\n            &quot;Zipcode&quot;: &quot;2312SX&quot;,\n            &quot;City&quot;: &quot;The Hague&quot;,\n            &quot;BirthDate&quot;: &quot;29\/10\/2019&quot;,\n            &quot;Language&quot;: &quot;Nederlands&quot;,\n            &quot;CustomerHasActiveMemberships&quot;: false,\n            &quot;TermsAccepted&quot;: false,\n            &quot;CompanyLocationId&quot;: 0,\n            &quot;CustomerLocations&quot;: [\n                {\n                    &quot;LocationId&quot;: 13653,\n                    &quot;LocationName&quot;: &quot;Sandbox Impressie&quot;,\n                    &quot;Status&quot;: &quot;Prospect&quot;\n                }\n            ]\n        },\n        {\n            &quot;CustomerId&quot;: 12889218,\n            &quot;FirstName&quot;: &quot;dfdfdf&quot;,\n            &quot;MiddleName&quot;: &quot;dfdfdf&quot;,\n            &quot;LastName&quot;: &quot;dfdfdf&quot;,\n            &quot;Email&quot;: &quot;jan@live.nl&quot;,\n            &quot;Address&quot;: &quot;blabblastreet&quot;,\n            &quot;HouseNumber&quot;: &quot;12&quot;,\n            &quot;Zipcode&quot;: &quot;2312LP&quot;,\n            &quot;City&quot;: &quot;Amsterdam&quot;,\n            &quot;BirthDate&quot;: &quot;29\/11\/2019&quot;,\n            &quot;Language&quot;: &quot;Nederlands&quot;,\n            &quot;CustomerHasActiveMemberships&quot;: false,\n            &quot;TermsAccepted&quot;: false,\n            &quot;CompanyLocationId&quot;: 0,\n            &quot;CustomerLocations&quot;: [\n                {\n                    &quot;LocationId&quot;: 13653,\n                    &quot;LocationName&quot;: &quot;Sandbox Impressie&quot;,\n                    &quot;Status&quot;: &quot;Prospect&quot;\n                }\n            ]\n        },\n        {\n            &quot;CustomerId&quot;: 12889206,\n            &quot;FirstName&quot;: &quot;dffddf&quot;,\n            &quot;MiddleName&quot;: &quot;dfdfdfdf&quot;,\n            &quot;LastName&quot;: &quot;dfdfdf&quot;,\n            &quot;Email&quot;: &quot;jan@live.nl&quot;,\n            &quot;Address&quot;: &quot;Teststreet&quot;,\n            &quot;HouseNumber&quot;: &quot;12&quot;,\n            &quot;Zipcode&quot;: &quot;2312LP&quot;,\n            &quot;City&quot;: &quot;Leiden&quot;,\n            &quot;BirthDate&quot;: &quot;28\/10\/2019&quot;,\n            &quot;Language&quot;: &quot;Nederlands&quot;,\n            &quot;CustomerHasActiveMemberships&quot;: false,\n            &quot;TermsAccepted&quot;: false,\n            &quot;CompanyLocationId&quot;: 0,\n            &quot;CustomerLocations&quot;: [\n                {\n                    &quot;LocationId&quot;: 13653,\n                    &quot;LocationName&quot;: &quot;Sandbox Impressie&quot;,\n                    &quot;Status&quot;: &quot;Prospect&quot;\n                }\n            ]\n        },\n    ],\n    &quot;error&quot;: {\n        &quot;HttpStatusCode&quot;: 200\n    }\n}<\/code><\/pre>\n<p>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?<\/p>\n","protected":false},"template":"","class_list":["post-14988880","topic","type-topic","status-publish","hentry","topic-tag-api","topic-tag-call","topic-tag-get","topic-tag-http","topic-tag-php"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/14988880","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/14988880\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=14988880"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}