PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Oct 17, 2019 6:43 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Mon Mar 03, 2014 3:11 pm 
Offline
Forum Newbie

Joined: Mon Mar 03, 2014 2:52 pm
Posts: 1
Syntax: [ Download ] [ Hide ]
I need have a gform submission POST to third party api as xmldata.

Url that data needs to POST to:

https://www.3rdparty.com/api/lead/inser ... ourxmldata

XML Format Needed (being pulled from gravity form below):


Syntax: [ Download ] [ Hide ]
         <crcloud>
           <lead>
            <type>Client</type>
            <firstname>Scott</firstname>
            <lastname>James</lastname>
            <client_assigned_to>Bill Smith</client_assigned_to>
           </lead>
          </crcloud>


Syntax: [ Download ] [ Hide ]
I have a curl function written but I am receiving a parsing error when posting. I have validated the xml and it is correct. I can also paste the xml data that prints out directly behind my url and get the result I want.


Syntax: [ Download ] [ Hide ]
 <?php
 
  add_action("gform_after_submission", "set_post_content", 10, 2);
  function set_post_content($entry, $form){
 
   
      function post_to_url($url, $post) {
         
          $fields = '';
         foreach($post as $key => $value) {
             $fields .= $key . '=' . $value . '&';
         }
         rtrim($fields, '&');
 
         $url = 'https://www.3rdparty.com/api/lead/insertRecord?apiauthkey=yourapikey&secretkey=yoursecretkey&xmlData=yourxmldata'.$xml;
 
 
         $post = curl_init();
 
         curl_setopt($post, CURLOPT_URL, $url);
         curl_setopt($post, CURLOPT_POST, count($data));
         curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
         curl_setopt($post, CURLOPT_SSL_VERIFYHOST, 0);
         curl_setopt($post, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($post, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
         curl_setopt($post, CURLOPT_VERBOSE, true);
 
         $verbose = fopen('php://temp', 'rw+');
         curl_setopt($post, CURLOPT_STDERR, $verbose);
 
         $result = curl_exec($post);
         echo $post; //Resource id #*** currently
         echo $result; //False 4404 XML parsing error currently
 
         rewind($verbose);
         $verboseLog = stream_get_contents($verbose);
         echo "Verbose information:\n<pre>", htmlspecialchars($verboseLog), "</pre>\n";
 
         curl_close($post);
     }
 
     if($form["id"] == 2){//sign up now
 
         $data = array(
             "type" =>     $entry["31"],      
 

       

    "firstname" =>     $entry["3"],
             "lastname" =>     $entry["4"],
             "client_assigned_to" =>     $entry["34"]);
 
 
         $xml = new SimpleXMLElement('<crcloud/>');
         $lead = $xml->addchild('lead');
         $data = array_flip($data);
         array_walk_recursive($data, array ($lead, 'addChild'));
 
         print $xml->asXML();
 
 
         post_to_url($url, $xml);
 
     }
 
 }
 
 ?>
 


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group