Ecommerce Shopify WordPress Discussion

PHP: List within an associative array for CURL data

I am looking to make a request from this API and am having some trouble. The example request is: curl --location '' --header 'Content-Type: application/json' --header 'Authorization: Bearer YOUR_ACCESS_TOKEN' --data '{"matchPersonInput": [{"firstName": "Henry","lastName": "Schuck","companyId": 346572700}],"outputFields": ["id","firstName","middleName","lastName"]}' I am implementing this in PHP, here is my code //ZoomInfo IP Enrich function zoominfo_email_enrich() { $zoominfo_token = $_GET['zoominfo_token']; $response = ""; $data = array( "matchPersonInput" => array( "emailAddress" => "", ), "outputFields" => array( "id", "firstName", "middleName", ) ); $postdata = json_encode($data); $ch = curl_init(""); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json','Authorization: ' . $zoominfo_token)); $response = curl_exec($ch); echo $response; die(); } However, this call results in error: "MatchPersonInput should be a list". I have also tried using $data = array( "matchPersonInput" => list( "emailAddress" => "", ) ); Which resulted in the WordPress site crashing. What is the proper way to format this data in PHP to not get an error back?
They are expecting more than one value for this key, note their example input, it's wrapped in square braces: "matchPersonInput": [ {"firstName": "Henry", "lastName": "Schuck", "companyId": 346572700} ] This way, you can specify more than one record: "matchPersonInput": [ {"firstName": "Henry", "lastName": "Schuck", "companyId": 346572700}, {"firstName": "Mary", "lastName": "Wilbur", "companyId": 12345} ] So even though you only have one matchPersonInput record in your code, you still need to make it into a list. In PHP terms, you need an indexed array of associative arrays. Just wrap your record in another layer of braces. I prefer the short array syntax for this: $data = [ "matchPersonInput" => [ ["emailAddress" => ""], ], "outputFields" => [ "id", "firstName", "middleName", ] ]; Then, if you want to add additional matches: $data = [ "matchPersonInput" => [ ["emailAddress" => ""], ["emailAddress" => ""], ["emailAddress" => ""], ], "outputFields" => [ "id", "firstName", "middleName", ] ];

February 26, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.