Jump to content


  • Posts

  • Joined

  • Last visited

jaybo's Achievements


Member (2/5)




Community Answers

  1. still to explore guzzle - but we have a resolution! The final code that we got to was indeed correct! The issue at that point was with the mailchimp audience logic. The emails that I was passing (made up emails) were causing the errors as they were invalid emails. I then was able to pass through real email addresses and this allowed the API request to process correctly. As previously discussed the Mailchimp API document for php is incomplete and using their API dashboard you cannot get more detailed error information. Contacting mailchimp and asking them to set up the API watcher for your account for 24-48hrs to check the API requests made during that period is one way of collecting that information.
  2. Great help thank you! I haven't done that before - limited use of Guzzle up to now. I will explore!
  3. You did indeed, Mailchimp responded back to me yesterday: So I sent through both requests (with and without the json_encode) for them to review and respond with error messages. It is unfortunate that they do not allow the api monitoring tool to be used on the client end.
  4. Code now; $operations = []; foreach($users as $user) { $operation = [ 'method' => 'POST', 'path' => "/lists/$listId/members", 'operation_id' => $user['id'], 'body' => json_encode([ 'email_address' => $user['email'], 'status' => $user['status'], // Create sync/button to allow BFCMA back end to change this with the DB to then update with daily/weekly batch request //add additional fields to insert into MC 'merge_fields' => [ // 8/10/21 Stackoverflow suggests to use merge-fields *not currently working with it included 'FNAME' => $user['fname'], 'LNAME' => $user['lname'] ] ]) ]; array_push($operations, $operation); } // create object to put $operations array inside $operationsObject = ['operations'=>$operations]; echo '<pre> '; print_r($operationsObject); echo '</pre>'; try { $response = $mailchimp->batches->start($operationsObject); // echo $response; echo '<pre> '; print_r($response); echo '</pre>'; } catch (\MailchimpMarketing\ApiException $e) { echo $e->getMessage(); } In addition, here is the final part of the code if you were to include the json_encode; // create object to put $operations array inside $operationsObject = ['operations'=>$operations]; echo '<pre> '; print_r($operationsObject); echo '</pre>'; $json = json_encode($operationsObject, JSON_PRETTY_PRINT); echo '<pre> '; print_r($json); echo '</pre>'; try { $response = $mailchimp->batches->start($json); // echo $response; echo '<pre> '; print_r($response); echo '</pre>'; } catch (\MailchimpMarketing\ApiException $e) { echo $e->getMessage(); }
  5. Thanks - yes I missed that one. After using print_r for $response and moving the $operationsObject after the array has been populated I get the following response indicating that there are no operations passed in the request; stdClass Object ( [id] => snxzha6dug [status] => pending [total_operations] => 0 [finished_operations] => 0 [errored_operations] => 0 [submitted_at] => 2022-01-11T00:42:23+00:00 [completed_at] => [response_body_url] => [_links] => Array ( [0] => stdClass Object ( [rel] => parent [href] => https://us6.api.mailchimp.com/3.0/batches [method] => GET [targetSchema] => https://us6.api.mailchimp.com/schema/3.0/Definitions/Batches/CollectionResponse.json [schema] => https://us6.api.mailchimp.com/schema/3.0/Paths/Batches/Collection.json ) [1] => stdClass Object ( [rel] => self [href] => https://us6.api.mailchimp.com/3.0/batches/snxzha6dug [method] => GET [targetSchema] => https://us6.api.mailchimp.com/schema/3.0/Definitions/Batches/Response.json ) [2] => stdClass Object ( [rel] => delete [href] => https://us6.api.mailchimp.com/3.0/batches/snxzha6dug [method] => DELETE ) ) ) If I also print_r $operationsObject then I get the following which again indicates an array, not an object; Array ( [operations] => Array ( [0] => Array ( [method] => POST [path] => /lists/6ecc1e6884/members [operation_id] => 1 [body] => {"email_address":"test1@example.com","status":"subscribed","merge_fields":{"FNAME":"David","LNAME":"Tester"}} ) [1] => Array ( [method] => POST [path] => /lists/6ecc1e6884/members [operation_id] => 2 [body] => {"email_address":"test2@example.com","status":"subscribed","merge_fields":{"FNAME":"Kevin","LNAME":"Ishere"}} ) [2] => Array ( [method] => POST [path] => /lists/6ecc1e6884/members [operation_id] => 3 [body] => {"email_address":"happy@example.com","status":"subscribed","merge_fields":{"FNAME":"Gerald","LNAME":"Happy"}} ) [3] => Array ( [method] => POST [path] => /lists/6ecc1e6884/members [operation_id] => 4 [body] => {"email_address":"Tim@example.com","status":"subscribed","merge_fields":{"FNAME":"Tim","LNAME":"Toolman"}} ) [4] => Array ( [method] => POST [path] => /lists/6ecc1e6884/members [operation_id] => 5 [body] => {"email_address":"grealish@example.com","status":"subscribed","merge_fields":{"FNAME":"Jack","LNAME":"Grealish"}} ) ) ) I tried to json_encode $operationsObject and then pass that through with the request, which appears to pass through the correct object format, but it returns the same $response message.
  6. response now= Fatal error: Uncaught Error: Object of class stdClass could not be converted to string in C:\xampp\htdocs\dashboard\MailchimpAPI\batchRequestAddMem.php:141 Stack trace: #0 {main} thrown in C:\xampp\htdocs\dashboard\MailchimpAPI\batchRequestAddMem.php on line 141 code now: $operations = []; // create object to put $operations array inside $operationsObject = ['operations'=>$operations]; foreach($users as $user) { $operation = [ 'method' => 'POST', 'path' => "/lists/$listId/members", 'operation_id' => $user['id'], 'body' => json_encode([ 'email_address' => $user['email'], 'status' => $user['status'], // Create sync/button to allow BFCMA back end to change this with the DB to then update with daily/weekly batch request //add additional fields to insert into MC 'merge_fields' => [ // 8/10/21 Stackoverflow suggests to use merge-fields *not currently working with it included 'FNAME' => $user['fname'], 'LNAME' => $user['lname'] ] ]) ]; array_push($operations, $operation); } try { $response = $mailchimp->batches->start($operationsObject); echo $response; } catch (\MailchimpMarketing\ApiException $e) { echo $e->getMessage(); }
  7. Yes I don't quite get how I do that. I have been reading the docs, specifically noting "expects a JSON object with a single key: operations, which is an array of objects that describe the API calls you want to make". I see, as you mentioned, that I have the $operations array all set. I have tried a couple of methods to create an object and then put the key:value pair inside, which is how I'm conceptualizing this part... // create object to put $operations array inside // $operationsObject = (object)['operations'=>$operations]; This brings about the same error. I feel I'm missing something that is more straight forward than what I am trying.
  8. Thank you again, I am drawing a blank - I tried to json decode each operation but that just prints an array of objects.
  9. requinix I'm back to this one and i'm still stumped. Trying to learn as I go - I am on my own with this and appreciate your pushing me to keep on learning. Do you have the next hint for me?
  10. I am seeing that $response returns bool(false). I have been trying to use SoapClient but continuously get the error: Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https...' I have looked in the php.ini file to address any exceptions and don't appear to get any success if I make adjustments there. This is the first time I have used SOAP and while it appears straight forward to me, I have some stumbling blocks to try to work though. As I have some experience of using cURL I have taken this route due to the resistance I am experiencing with SoapClient.
  11. I am sending a SOAP request and the response is 200 ok but I am struggling to output the $response. This is the website for the request Calculator Web Service and also the xml file document tree http://dneonline.com/calculator.asmx?wsdl Here is my php code; <?php $xml = '<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <Add xmlns="http://tempuri.org/"> <intA>1</intA> <intB>2</intB> </Add> </soap:Body> </soap:Envelope>'; $url = "http://dneonline.com/calculator.asmx?wsdl"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $headers = array(); array_push($headers, "Content-Type: text/xml; charset=utf-8"); array_push($headers, "Accept: text/xml"); array_push($headers, "Cache-Control: no-cache"); array_push($headers, "Pragma: no-cache"); array_push($headers, "SOAPAction: http://tempuri.org/Add"); if($xml != null) { curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml"); array_push($headers, "Content-Length: " . strlen($xml)); } // curl_setopt($ch, CURLOPT_USERPWD, "user_name:password"); /* If required */ curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); echo "<pre>"; print_r($response->AddResponse); echo "</pre>"; ?>
  12. Makes complete sense - thank you Barand. Thank you for your input also ginerjm.
  13. I have a stdClass Object that I need to then point to a single value within it. Here is the object returned saved in variable named $response: stdClass Object ( [data] => stdClass Object ( [result] => Array ( [0] => stdClass Object ( [label] => FC#### **[value] => 72144** ) [1] => stdClass Object ( [label] => SERVICE [value] => 72123 ) [2] => stdClass Object ( [label] => all_ssid [value] => all_ssid ) ) [defaultValue] => all_ssid ) [msg] => [retCode] => 0 ) How do I then point to [value] => 72144 I understand that the path is $response->data->result->0->value but don’t know how what to use for the “0” pointing to the 1st array result. I have tried $response->data->result->{‘value’} which returns " Warning: Attempt to read property “label” on array".
  14. Yes it was. Found an answer that worked - I added JSON_UNESCAPED_SLASHES when encoding the data. $body = json_encode($body_data, JSON_UNESCAPED_SLASHES); Also unquoted the networkAdministrators array values and the call was successful.
  15. I am sending an API call to GWN API network/create endpoint and my payload is an array as below; $body_data = array( 'networkName' => 'BFCMA_55_ChaitAdam', 'country' => 'US', 'timezone' => 'America/New_York', 'networkAdministrators' => array( '13497', '13788' ), 'cloneNetworkId' => 29652 ); When I echo $body_data the output is; {“networkName”:“BBC_55”,“country”:“US”,“timezone”:“America\/New_York”,“networkAdministrators”:[“12345”,“13456”],“cloneNetworkId”:02345} I need the timezone to be “America/New_York” NOT “America\/New_York” as is outputted. How do I do that?
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.