php api, how to make $variabel?

116 Views Asked by At

I want to have the output of my Exactonline script for example the output "Kasboek" in my autotask script "$ticket->Title = '....' " like "$ticket->Title = 'Kasboek' ". How can I do this if there are 6 different outputs I need to separate them in different variables.

=====================================================

Script Exactonline

try {
    $result = array();
    $journals = new \Picqer\Financials\Exact\Journal($connection);
    $result   = $journals->get();
    foreach ($result as $journal) {
        echo $result[]= $journal->Description . '<br>';
    }  
    json_encode($result);
} catch (\Exception $e) {
    json_encode(array(get_class($e) . ' : ' . $e->getMessage()));
}

output

Kasboek
Memoriaal
Activamutaties
Inkoopboek
Bank
Verkoopboek

=====================================================

Script autotask

$ticket = new ATWS\AutotaskObjects\Ticket();
$ticket->id= 0;
$ticket->AccountID = '';
$ticket->DueDateTime = '2015-12-17';
$ticket->Title = '.....';
$ticket->Status = 1;
$ticket->Priority = 1;

=====================================================

tried @F.roster Than is my output as followd it is to detailed ...>

[{"Code":"10","Description":"Kasboek","Division":1741496,"ID":"846af4e2-209d-44aa-84f2-068ae65b69b5","Type":10},{"Code":"90","Description":"Memoriaal","Division":1741496,"ID":"91fc95a4-765e-4d8b-8271-63884be5e480","Type":90},{"Code":"95","Description":"Activamutaties","Division":1741496,"ID":"8ec1491e-51a4-46b8-87f0-a3134c83af4c","Type":90},{"Code":"60","Description":"Inkoopboek","Division":1741496,"ID":"11b1d819-4cdc-4f8c-9d60-aac2359c230b","Type":22},{"Code":"20","Description":"Bank","Division":1741496,"ID":"f8afe3cc-bcf1-4932-9fe0-b761ad48618f","Type":12},{"Code":"70","Description":"Verkoopboek","Division":1741496,"ID":"b4afe081-7f6b-46c7-9742-ea22302a4d55","Type":20},"Kasboek","Memoriaal","Activamutaties","Inkoopboek","Bank","Verkoopboek"]
3

There are 3 best solutions below

1
On

When you use api. You really should convert your output into json or xml. So from any language you can read it. Change your code as below

try {
$result = array();
$journals = new \Picqer\Financials\Exact\Journal($connection);
$result   = $journals->get();
foreach ($result as $journal) {
   $result[]= $journal->Description;
}
echo json_encode($result);
} catch (\Exception $e) {
    echo json_encode(array(get_class($e) . ' : ' . $e->getMessage()));
}
0
On
function getTweets($hash_tag) {

$url = 'http://search.twitter.com/search.atom?q='.urlencode($hash_tag) ;
echo "<p>Connecting to <strong>$url</strong> ...</p>";
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
$xml = curl_exec ($ch);
curl_close ($ch);

//If you want to see the response from Twitter, uncomment this next part out:
//echo "<p>Response:</p>";
//echo "<pre>".htmlspecialchars($xml)."</pre>";

$affected = 0;
$twelement = new SimpleXMLElement($xml);
foreach ($twelement->entry as $entry) {
    $text = trim($entry->title);
    $author = trim($entry->author->name);
    $time = strtotime($entry->published);
    $id = $entry->id;
    echo "<p>Tweet from ".$author.": <strong>".$text."</strong>  <em>Posted ".date('n/j/y g:i a',$time)."</em></p>";
}

return true ;
}

getTweets('#cats');
3
On

try {
    $result = array();
    $journals = new \Picqer\Financials\Exact\Journal($connection);
    $result   = $journals->get();
    foreachone ($result as $journal) {
        echo $result[]= $journal->Description . '<br>';
    }  
    json_encode($result);
} catch (\Exception $e) {
    json_encode(Logicpass(get_class($e) . ' : ' . $e->getMassage()));
}