Post

1 follower Follow
0
Avatar

writing my api calls to csv files

i can authenticate, make API calls i just cannot seem to be able to write them to a csv file in an organized way. any suggestions on the code

<?php ob_start("ob_gzhandler");?>

<html>

<header>Authorize with Username and Pass</header>

<body>

<?php

require_once('config.php');

require_once('PodioAPI.php');

require_once('examples/username_password_auth.php');

?>

<?php

// initializing or creating array

$contact_info = PodioContact::get_all($attributes = array() );

// creating object of SimpleXMLElement

$xml_contact_info = new SimpleXMLElement("<?xml version=\"1.0\"?><contact\_info></contact\_info>");

// function call to convert array to xml

array_to_xml($contact_info,$xml_contact_info);

//saving generated xml file

$xml_contact_info->asXML('Contacts.xml');

// function defination to convert array to xml

function array_to_xml($contact_info, &$contact_info) {

foreach($contact_info as $key => $value) {

if(is_array($value)) {

if(!is_numeric($key)){

$subnode = $xml_contact_info->addChild("$key");

array_to_xml($value, $subnode);

}

else{

array_to_xml($value, $xml_contact_info);

}

}

else {

$xml_contact_info->addChild("$key","$value");

}

}

}

?>

</body>

</html> 

Nick George Answered

Please sign in to leave a comment.

2 comments

0
Avatar

Nick, I think you will need to provide some more details... :)

Having errors?  What is the problem exactly... ?

Patrick Steil

http://www.podiotools.com 

Patrick Steil 0 votes
0
Avatar

Hi Nick,

If you are getting data out from Podio (and you would get a very nasty error message if you weren't) the problem lies not with the Podio API part of your code, but with the XML building etc. In that case you can get much better help in a dedicated PHP programmer forum than here where we focus on the Podio API specifically.

All the best,

Andreas

Andreas Haugstrup Pedersen 0 votes