Jump to content

unplugged_web

Members
  • Posts

    897
  • Joined

  • Last visited

Everything posted by unplugged_web

  1. There's no difference in the PHP at all. The only difference is one form calls is using JQuery (that one works) and the other is called on the same page (that doesn't work)
  2. Sorry I didn't mean to create duplicate post, I thought that they might not be similar enough. $contact contains the details of everybody in that book, $data contains the details from the form but $book is empty. This works perfectly if I call it like this: $.ajax({type: 'POST',url: '/api.php',data: $("#form").serialize(),success: function(data) {if(data == "true") {$("#form").fadeOut("fast", function(){$(this).before("<div class='thanks'><strong>Thank you you've been added to our mailing list</strong></div>");});}if(data == "false") {$("#form").fadeOut("fast", function(){$(this).before("<div class='thanks'><strong>You are already subscribed mailing list.</strong></div>");}); but this time I need to call it in the same file but it doesn't work
  3. Sorry here it is: <?php//Function to initiate curl, set curl options, execute and return the responsefunction execute_post($url, $data){ //encode the data as json string $requestBody = json_encode($data, true); //initialise curl session $ch = curl_init(); //curl options curl_setopt($ch, CURLAUTH_BASIC, CURLAUTH_DIGEST); curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'password'); curl_setopt($ch, CURLOPT_GETFIELDS, $requestBody); curl_setopt($ch, CURLOPT_GET, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Accept: ' . 'application/json' ,'Content-Type: application/json')); //curl execute and json decode the response $responseBody = json_decode(curl_exec($ch)); //close curl session curl_close($ch); return $responseBody;}?>
  4. Why is the $book variable empty? I've checked everything before it and up until that point everything is correct. I've even tried renaming it but that didn't work <?php $postContactUrl = 'https://apiconnector.com/v2/contacts/'; $data = array( 'Email' => $_POST['email'], 'EmailType' => 'Html', 'dataFields' => array( array( 'Key' => 'FULLNAME', 'Value' => $_POST['name_first']." ".$_POST['name_last'] ), ) ); $contact = execute_post($postContactUrl, $data); $addContactToAddressBookUrl = 'https://apiconnector.com/v2/address-books/' . '123456' . '/contacts'; $book = execute_post($addContactToAddressBookUrl, $contact); echo "<pre>" . print_r($book, true) . "</pre>"; ?>
  5. I think I have have discovered where the problem is. When I use print_r on $data it prints the results, $contact again works but $book prints nothing at all. I don't know what the reason for $book not showing anything. I tried renaming it incase it was conflicting with something I wasn't aware of but that didn't make any difference. Does anybody have any suggestion as to why this isn't working?
  6. REST.phpYes that's in the rest of a file, I've attached the file as there's too much code to post here
  7. I'm sorry to bother you again, but I finally managed to get it to work. Dotmailer didn't seem to except it no matter what I did so in the end I used REST to get it working. If I submit the form using AJAX it works and sends all of the data to dotmailer but if I try to send it on the same page I either get a PHP Fatal error: Call to undefined function execute_post() error or if I move the function to before (or after) I call it the form is sent to the database but nothing is sent to dotmailer. I'm really desperate to get this sorted as is my boss but I've spent a week trying to get it to work on the same page but am not getting anywhere. If you don't mind I've attached the file with the code that is executed after the form (which is on the same page) is submitted as well as the function I'm having the issue with. I've tried to define the function before and after but neither work. If I define it straight after the $book = execute_post($addContactToAddressBookUrl, $contact); line then I get the fatal error. I'd be so grateful if you could help one last time on this please. REST.php
  8. I've very new to PHP and am trying to get API (REST) to work with a site I'm currently working on. It works if I submit a form using AJAX but I want it to work without using AJAX. The code I'm using is: <?php $postContactUrl = 'https://apiconnector.com/v2/contacts/'; $data = array( 'Email' => $_POST['email'], 'EmailType' => 'Html', 'dataFields' => array( array( 'Key' => 'FULLNAME', 'Value' => $_POST['name_first']." ".$_POST['name_last'] ), ) ); $contact = execute_post($postContactUrl, $data); $addContactToAddressBookUrl = 'https://apiconnector.com/v2/address-books/' . '123456' . '/contacts'; $book = execute_post($addContactToAddressBookUrl, $contact); function execute_post($url, $data){ $requestBody = json_encode($data, true); $ch = curl_init(); curl_setopt($ch, CURLAUTH_BASIC, CURLAUTH_DIGEST); curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'password'); curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Accept: ' . 'application/json' ,'Content-Type: application/json')); $responseBody = json_decode(curl_exec($ch)); curl_close($ch); return $responseBody; } ?> but when I try to add that to the page the form is on I get this error: PHP Fatal error: Call to undefined function execute_post() I've tried to fix it but nothing I do seems to work. I don't understand why it works with AJAX but not any other way. I tried moving the function to before I called it but neither this: function execute_post(){ ... } $contact = execute_post($postContactUrl, $data); nor this worked: function execute_post(){ $contact = execute_post($postContactUrl, $data);
  9. Just incase anybody else is having the same problem this is the solution I used in the end: $data = array( 'Email' => $_POST['email'], 'EmailType' => 'Html', 'dataFields' => array( array( 'Key' => 'FIRSTNAME', 'Value' => $_POST['first']), array( 'Key' => 'LASTNAME', 'Value' => $_POST['last']), array( 'Key' => 'FULLNAME', 'Value' => $_POST['first']." ".$_POST['last'] ), array( 'Key' => 'GENDER', 'Value' => $_POST['gender']), ));
  10. Brilliant thank you, I thought that all array values had to be in quotation marks! Is it the same if I want to send numbers then (i.e. I don't need the quotations)?
  11. I've managed to get most of it to work but didn't know if it's possible to use $_GET['email'] in an array? For example: $data = array( 'Email' => '$_GET['email']', 'EmailType' => 'Html', outputs: [email] => $_GET['email'] [optInType] => Unknown [emailType] => Html instead
  12. I'm very new to this but am trying to add a user (and their details for an address book with dotmailer. The code I'm using, which excepts the email address okay (a new contact is created). The problem is I'm also trying to add their name, gender, address etc to the contact. To add the data I'm using: <?php/** POST EMAIL FIRST AND GET CONTACT FROM DOTMAILER */$postContactUrl = 'https://apiconnector.com/v2/contacts/';$data = array( 'Email' => 'test@email', 'EmailType' => 'Html', 'dataFields' => array('key' => 'FIRSTNAME','value'=> 'Fred','key' => 'LASTNAME','value'=> 'Smith','key' => 'FULLNAME','value'=> 'Fred Smith','key' => 'GENDER','value'=> 'Male',));//post email and response will be contact object from dotmailer$contact = execute_post($postContactUrl, $data);/** ADD CONTACT TO ADDRESS BOOK */$addContactToAddressBookUrl = 'https://apiconnector.com/v2/address-books/' . '123456' . '/contacts'; //post contact to address book and response will be address book object from dotmailer$book = execute_post($addContactToAddressBookUrl, $contact);// echo "<pre>" . print_r($contact, true) . "</pre>"; echo "<pre>" . print_r($book, true) . "</pre>";function execute_post($url, $data){ $requestBody = json_encode($data, true); $ch = curl_init(); curl_setopt($ch, CURLAUTH_BASIC, CURLAUTH_DIGEST); curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'password'); // credentials curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Accept: ' . 'application/json' ,'Content-Type: application/json')); $responseBody = json_decode(curl_exec($ch)); curl_close($ch); return $responseBody;}?> The var_dump($book); shows no data at all for any of the dataFields: stdClass Object( [id] => 123456789 [email] => test@email [optInType] => Unknown [emailType] => Html [dataFields] => Array ( [3] => stdClass Object ( [key] => FIRSTNAME [value] => ) [4] => stdClass Object ( [key] => FULLNAME [value] => ) [5] => stdClass Object ( [key] => GENDER [value] => ) [7] => stdClass Object ( [key] => LASTNAME [value] => ) ) This is what I'm trying to do: http://api.dotmailer.com/v2/help/wadl#AddressBookContacts (PostAddressBookContacts in particular) but have now hit a wall and am not getting anywhere.
  13. After continuing to search Google I came across somebody saying that I should be using 'call' with an array so I changed it to this: $result=$proxy->call('GetAddressBooks',array('select' => 200, 'skip'=>0)); and echo "<pre>" . print_r($result, true) . "</pre>"; That then gave me an array, part of which is this: but I don't know how to get that in a format that is more readable for people
  14. I've been told that I have to use NuSOAP unfortunately. Later this year our servers will be reconfigured to use SOAP but until then I have to use this sadly.
  15. I'm sorry I don't really understand. I'm just so desperate to get this sorted. I'm more than happy to pay for this to be sorted. My boss keeps asking about this and dotmailer themselves are no help at all. I'm just worried about keeping my job. Before I started the job I told them I'd had no experience of API's at all but now they want me to get this sorted. As I say I'm just desperate now.
  16. I finally got an example from dotmailer but don't know how to adapt it into NUSOAP. This is what they sent me: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v2="http://apiconnector.com/v2"><soapenv:Header/><soapenv:Body><v2:GetAddressBooks><v2:select>?</v2:select><v2:skip>?</v2:skip></v2:GetAddressBooks></soapenv:Body></soapenv:Envelope> and said that I can use this to help: http://api.dotmailer.com/v2/api.svc#op.ApiService.GetAddressBooks
  17. I know they're not very helpful at all!! I tried that but it gave me this error: PHP Fatal error: Call to undefined method nusoap_proxy_1701592316::GetAddressBooksResponse()
  18. If the number is zero then nothing happens at all. If the number is lower than what's there but not zero then it deducts it from the online stock again (instead of adding it back the difference)
  19. I've got a huge (pre-populated) form that it used for keep track of stock. The problem is that I've added a field for stock for the shop and want to update the online stock depending on which product was changed. The problem is that people won't be changing one product at a time but could be change 10, 20, 100 or whatever so I ned to make sure that the right product is updated. Also the number could go up as well as down and should also adjust the online stock depending on what entered in the shop field for that product. So far it works if one product has it's shop stock increased. It doesn't work if it decreases or if multiple products are changed. This is what I've got at the moment: if( isset( $_POST['shop-1-'.$row['id']] ) && ctype_digit( $_POST['shop-1-'.$row['id']] ) ) {if ( $row['shop'] > $_POST['shop-1-'.$row['id']] ) { // checks if the shop stock is higher $query="update stock set online=online+".$_POST['shop-1-'.$row['id']].",shop=".$_POST['shop-1-'.$row['id']].",shop_date=".time()." where id=".$row['id']; dbUpdate( $query,"dbLinkInt" );} elseif ( $row['shop'] < $_POST['shop-1-'.$row['id']] ) { // checks if the shop stock is lower $query="update stock set online=online-".$_POST['shop-1-'.$row['id']].",shop=".$_POST['shop-1-'.$row['id']].",shop_date=".time()." where id=".$row['id']; dbUpdate( $query,"dbLinkInt" );} elseif ( $row['shop'] == $_POST['shop-1-'.$row['id']] ) { // checks if the shop stock doesn't change }} Thanks in advanced for any help with this.
  20. I know I posted before about this, but I didn't know that was with the old API. I spoke to dotmailer about their examples and they said that the API has moved on significantly since these articles were last updated. They also have a new version of the API and will be updating the examples soon. They also said that the 'Get' value is the number of objects you want returned and the 'Skip' value is the number of address books you wish to skip at each time the call is run. I tried to follow what their documentation here says. I changed the code to this: $result=$proxy->GetAddressBooksResponse->GetAddressBooksResult(array ('count' => 30)); but that just gives me a fatal error. I'm really trying to learn this but don't understand a lot of it.
  21. That's what they say in their example but after speaking to them they said that the call should only consist of a select and skip values as parameters and that this should give you an output. Now I'm really confused about how to do it. I did try using select and skip but didn't get anything so I guess I did something wrong with it
  22. I can now see the username and password (after using setCredentials) but I'm still not seeing any actual data, i.e. the address books
  23. I used $client->setCredentials("user","password"); to send the login details, but I'm not getting any details at all. I'm using AddressBooks( $result ); to display the results. The function for that is: function AddressBooks( $result ) { print "<table><tr><th></th><th>Id</th><th>Name</th><th>Visibility</th><th>Contacts</th></tr>";$array = $result->GetAddressBooksResponse->GetAddressBooksResult;foreach($array as $k=>$v){print "<tr><td align='right'>" . ($k+1) . "</td><td>" . $v->Id . "</td><td>" . $v->Name . "</td><td align='right'>" . $v->Visibility . "</td><td align='right'>" . $v->Contacts . "</td></tr>";}print "</table>"; } ?> but all I get it is the table with the headers, nothing is entered at all for the rows.
  24. Sorry to ask but how would I send them properly? I spoke to dotmailer about getting contacts in a particular address book and they said that this was correct for that: <?php$client = new SoapClient("https://apiconnector.com/v2/api.svc?wsdl");$params = array("login" => "username","password" => "password");$result =$client->GetContactsInAddressBookResponse(array('withFullData'));$array =$result->GetContactsInAddressBookResponse->GetContactsInAddressBookResult;print "<table border='2'><tr><th></th><th>addressBookId</th><th>withFullData</th></tr>";foreach($array as $k=>$v){print "<tr><td align='right'>" . ($k+1) . "</td><td>" . $v->addressBookId . "</td><td align='right'>" . $v->withFullData . "</td></tr>";}print "</table>";?> I know it's getting different information but I've tried sending the username/password in the same way (I've tried using login as well as username) and neither of them work
×
×
  • Create New...