Jump to content

jaybo

Members
  • Posts

    46
  • Joined

  • Last visited

Everything posted by jaybo

  1. Great help thank you! I haven't done that before - limited use of Guzzle up to now. I will explore!
  2. 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.
  3. 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(); }
  4. 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.
  5. 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(); }
  6. 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.
  7. Thank you again, I am drawing a blank - I tried to json decode each operation but that just prints an array of objects.
  8. 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?
  9. 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.
  10. 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>"; ?>
  11. Makes complete sense - thank you Barand. Thank you for your input also ginerjm.
  12. 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".
  13. 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.
  14. 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?
  15. I am sending a POST request and the request body is the string containing the JSON. These are both within the $operation array. I am not sure how to begin to structure this. 🤔
  16. Thank you requinix, where exactly do I place that? I attempted to add it in the $operation array which returned the same error.
  17. Working with Mailchimp API, I'm trying to add contacts without success by sending in PHP Async Request batch call to their endpoint. I've gone trough their documentation may times but still without success, trying to replicate their example. https://mailchimp.com/developer/marketing/guides/run-async-requests-batch-endpoint/ I am using the php sdk. Would be great if someone could point me in the right direction why the second example is not working. #################START OF CODE ############################# <?php require_once('vendor/autoload.php'); require_once('config.php'); include 'dbh.php'; include 'testDbh.php'; $mailchimp = new MailchimpMarketing\ApiClient(); $mailchimp->setConfig([ 'apiKey' => $key, 'server' => $server ]); // build json array from mysql db $users = []; $conn = mysqli_connect("localhost","root","","mailchimpapi"); //check connection if(!$conn){ echo "Failed to connect to MySQL: " . mysqli_connect_error(); exit(); }else{ echo 'Connection Successful! <br><br>'; } $sql = "SELECT * FROM mailchimpbatch"; //mysqli write query and get result $results = mysqli_query($conn, $sql); $users = mysqli_fetch_all($results, MYSQLI_ASSOC); $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'], 'merge_fields' => 'FNAME' => $user['fname'], 'LNAME' => $user['lname'] ] ]) ]; array_push($operations, $operation); } try { $response = $mailchimp->batches->start($operations); echo $response; } catch (\MailchimpMarketing\ApiException $e) { echo $e->getMessage(); } ############################END OF CODE ########################## Here is the print_r of $users I pull from the database (made up people); Array ( [0] => Array ( [id] => 1 [status] => subscribed [email] => test1@example.com [fname] => David [lname] => Tester ) [1] => Array ( [id] => 2 [status] => subscribed [email] => test2@example.com [fname] => Kevin [lname] => Ishere ) [2] => Array ( [id] => 3 [status] => subscribed [email] => happy@example.com [fname] => Gerald [lname] => Happy ) [3] => Array ( [id] => 4 [status] => subscribed [email] => Tim@example.com [fname] => Tim [lname] => Toolman ) [4] => Array ( [id] => 5 [status] => subscribed [email] => grealish@example.com [fname] => Jack [lname] => Grealish ) ) The error I receive is a 400 BAD REQUEST, INVALID RESOURCE (full error returned is at the bottom of this post). *****Upon reaching out to Mailchimp they responded with the following: While we are unable to assist with editing or making PHP calls, we can see the Request is being sent over as an array, and does not have any reference to the required "operations". For example, we would expect to see something like: ``` { "operations": [ { "method": "POST", "path": "\/lists\/$listID\/members", "operation_id": "1", "body": "{\"email_address\":\"test1@example.com\",\"status\":\"subscribed\",\"merge_fields\":{\"FNAME\":\"David\",\"LNAME\":\"Tester\"}}" } ] } ``` The request must be an object, rather than an array. So now I am working on that change, but i'm unsure how to implement that - any ideas? ################################################################### *Full error returned = **Fatal error**: Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://us6.api.mailchimp.com/3.0/batches` resulted in a `400 Bad Request` response: {"type":"https://mailchimp.com/developer/marketing/docs/errors/","title":"Invalid Resource","status":400,"detail":"The r (truncated...) in C:\xampp\htdocs\dashboard\MailchimpAPI\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php:113 Stack trace: #0 C:\xampp\htdocs\dashboard\MailchimpAPI\vendor\guzzlehttp\guzzle\src\Middleware.php(69): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response), NULL, Array, NULL) #1 C:\xampp\htdocs\dashboard\MailchimpAPI\vendor\guzzlehttp\promises\src\Promise.php(204): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response)) #2 C:\xampp\htdocs\dashboard\MailchimpAPI\vendor\guzzlehttp\promises\src\Promise.php(153): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), NULL) #3 C:\xampp\htdocs\dashboard\MailchimpAPI\vendor\guzzlehttp\promises\src\TaskQueue.php(48): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}() #4 C:\xampp\htdocs\dashboard\MailchimpAPI\vendor\guzzlehttp\promises\src\Promise.php(248): GuzzleHttp\Promise\TaskQueue->run(true) #5 C:\xampp\htdocs\dashboard\MailchimpAPI\vendor\guzzlehttp\promises\src\Promise.php(224): GuzzleHttp\Promise\Promise->invokeWaitFn() #6 C:\xampp\htdocs\dashboard\MailchimpAPI\vendor\guzzlehttp\promises\src\Promise.php(269): GuzzleHttp\Promise\Promise->waitIfPending() #7 C:\xampp\htdocs\dashboard\MailchimpAPI\vendor\guzzlehttp\promises\src\Promise.php(226): GuzzleHttp\Promise\Promise->invokeWaitList() #8 C:\xampp\htdocs\dashboard\MailchimpAPI\vendor\guzzlehttp\promises\src\Promise.php(62): GuzzleHttp\Promise\Promise->waitIfPending() #9 C:\xampp\htdocs\dashboard\MailchimpAPI\vendor\guzzlehttp\guzzle\src\Client.php(123): GuzzleHttp\Promise\Promise->wait() #10 C:\xampp\htdocs\dashboard\MailchimpAPI\vendor\mailchimp\marketing\lib\Api\BatchesApi.php(538): GuzzleHttp\Client->send(Object(GuzzleHttp\Psr7\Request), Array) #11 C:\xampp\htdocs\dashboard\MailchimpAPI\vendor\mailchimp\marketing\lib\Api\BatchesApi.php(527):
  18. I want to listen to the callback event " signature_request_all_signed " - how do I code this? After that I then will use the below code to GET the completed document: $client = new HelloSign\Client('SIGN_IN_AND_CREATE_API_KEY_FIRST'); $client->getFiles('fa5c8a0b0f492d768749333ad6fcc214c111e967', $dest_file_path, HelloSign\SignatureRequest::FILE_TYPE_PDF); Documentation is here https://app.hellosign.com/api/signatureRequestWalkthrough#GetStatus
  19. from using tail -f /var/log/httpd/error_log httpd log returns no errors. Also inputting error_reporting(E_ALL); on script runtime returns nothing also. php.ini file is also updated to error_log ON.
  20. I have created a template with Docusign API using a base document (a customer contract) the details of which will change when I send out an envelope but the layout will remain the same. I am trying to replace the base document from the template when creating the envelope. I have been informed that I need to use composite templates but when I try to code that I am getting a 500 error. Here is the code for the envelope definition: * @param $args array * @return array ['redirect_url'] * @throws ApiException for API problems and perhaps file access \Exception too. */ # ***DS.snippet.0.start private function worker(array $args): array { # 1. Create the envelope request object $envelope_definition = $this->make_envelope($args["envelope_args"]); # 2. call Envelopes::create API method # Exceptions will be caught by the calling function $envelope_api = $this->clientService->getEnvelopeApi(); $results = $envelope_api->createEnvelope($args['account_id'], $envelope_definition); return ['envelope_id' => $results->getEnvelopeId()]; } /** * Creates envelope definition using composite templates * Parameters for the envelope: signer_email, signer_name, signer_client_id * * @param $args array * @return mixed -- returns an envelope definition */ private function make_envelope(array $args): EnvelopeDefinition { $signer = new \DocuSign\eSign\Model\Signer([ 'email' => $args['signer_email'], 'name' => $args['signer_name'], 'role_name' => "signer", 'recipient_id' => "1", # Adding clientUserId transforms the template recipient # into an embedded recipient: 'client_user_id' => $args['signer_client_id'] ]); # Create the company signer recipient $companySigner = new \DocuSign\eSign\Model\Signer([ 'email' => $args['companySigner_email'], 'name' => $args['companySigner_name'], 'role_name' => "companySigner", 'recipient_id' =>"2" ]); # Recipients object: $recipients_server_template = new \DocuSign\eSign\Model\Recipients([ 'signers' => [$signer, $companySigner]]); # Create a composite template for the Server template + roles $comp_template1 = new \DocuSign\eSign\Model\CompositeTemplate([ 'composite_template_id' => "1", 'server_templates' => [ new \DocuSign\eSign\Model\ServerTemplate([ 'sequence' => "1", 'template_id' => $args['template_id']]) ], # Add the roles via an inlineTemplate 'inline_templates' => [ new \DocuSign\eSign\Model\InlineTemplate([ 'sequence' => "1", 'recipients' => $recipients_server_template]) ] ]); # Create Signer definitions for the added document - using the same tabs from server template $signerAddedDoc = new \DocuSign\eSign\Model\Signer([ 'email' => $args['signer_email'], 'name' => $args['signer_name'], 'role_name' => "signer", 'recipient_id' => "1", 'client_user_id' => $args['signer_client_id'], 'tabs' => $signer_tabs]); $companySignerAddedDoc = new \DocuSign\eSign\Model\Signer([ 'email' => $args['companySigner_email'], 'name' => $args['companySigner_name'], 'role_name' => "companySigner", 'recipient_id' => "2", 'client_user_id' => $args['signer_client_id'], 'tabs' => $companySigner_tabs]); # The Recipients object for the added document. # Using companySigner definition from above. $recipients_added_doc = new \DocuSign\eSign\Model\Recipients([ 'signers' => [$signerAddedDoc, $companySignerAddedDoc]]); # Create the pdf document that will be added to the envelope $doc_file = 'Connect_Customer_Agreement.pdf'; $content_bytes = file_get_contents(self::DEMO_DOCS_PATH . $doc_file); $base64_file_content = base64_encode($content_bytes); # Create the document model $document = new Document([ # create the DocuSign document object 'document_base64' => $base64_file_content, 'name' => 'Prepared Connect Customer Agreement', # can be different from actual file name 'file_extension' => 'pdf', # many different document types are accepted 'document_id' => '1' # a label used to reference the doc # Create a composite template for the added document $comp_template2 = new \DocuSign\eSign\Model\CompositeTemplate([ 'composite_template_id' => "2", # Add the recipients via an inlineTemplate 'inline_templates' => [ new \DocuSign\eSign\Model\InlineTemplate([ 'sequence' => "2", 'recipients' => $recipients_added_doc]) ], 'document' => $document]); # Create the envelope definition with the composited templates $envelope_definition = new \DocuSign\eSign\Model\EnvelopeDefinition([ 'status' => "sent", 'composite_templates' => [$comp_template1, $comp_template2] ]); return $envelope_definition;
×
×
  • 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.