0

I am using the php library from here and I have a small problem.

To get some info for a invoice 118868, I can do this

<?php
$invoice_id=118868;

$invoice=$freshbooks->invoiceGet($invoice_id);
print_r($invoice);
?>

This is the output for print_r

Class Object ( [@attributes] => stdClass Object ( [status] => ok ) [invoice] => stdClass Object ( [invoice_id] => 00000219023 [estimate_id] => stdClass Object ( ) [number] => 8822 [client_id] => 83 [contacts] => stdClass Object ( [contact] => stdClass Object ( [contact_id] => 0 ) ) [recurring_id] => stdClass Object ( ) [organization] => Jimmy Thwart [first_name] => stdClass Object ( ) [last_name] => stdClass Object ( ) [p_street1] => stdClass Object ( ) [p_street2] => stdClass Object ( ) [p_city] => stdClass Object ( ) [p_state] => stdClass Object ( ) [p_country] => stdClass Object ( ) [p_code] => stdClass Object ( ) [po_number] => 10002 [status] => sent [amount] => 16.90 [amount_outstanding] => 16.90 [paid] => 0.00 [date] => 2013-01-31 00:00:00 [notes] => stdClass Object ( ) [terms] => Your slot can only be secured upon payment. Any reservation made before payment will only be guaranteed for 2 days. [discount] => 0 [url] => https://example.freshbooks.com/view/vgPb2TNGCR7n8JV [auth_url] => https://example.freshbooks.com/invoices/219023 [links] => stdClass Object ( [client_view] => https://example.freshbooks.com/view/vgPb2TNGCR7n8JV [view] => https://example.freshbooks.com/invoices/219023 [edit] => https://example.freshbooks.com/invoices/219023/edit ) [return_uri] => stdClass Object ( ) [updated] => 2013-01-31 02:25:13 [currency_code] => SGD [language] => en [vat_name] => stdClass Object ( ) [vat_number] => stdClass Object ( ) [folder] => active [staff_id] => 1 [lines] => stdClass Object ( [line] => stdClass Object ( [line_id] => 1 [name] => Lady 1pax [description] => Services (1 pax) [unit_cost] => 16.90 [quantity] => 1 [amount] => 16.90 [tax1_name] => stdClass Object ( ) [tax2_name] => stdClass Object ( ) [tax1_percent] => 0 [tax2_percent] => 0 [compound_tax] => 0 [type] => Item ) ) [gateways] => stdClass Object ( [gateway] => stdClass Object ( [name] => PayPal ) ) ) ) 

I hope the output can only be the URL and not this whole chunk of code. Output wanted:

https://example.freshbooks.com/view/vgPb2TNGCR7n8JV

However, it lists all information of the invoice. How do I get only the invoice URL?

Shobhit Puri
  • 25,769
  • 11
  • 95
  • 124
Emerson F
  • 805
  • 3
  • 9
  • 17

2 Answers2

0

Well, using the output of your code, you can see what the elements of $invoice are. Use the one that you need.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • do you think it's an answer? Why won't you use comments for this instead? – KennyPowers Jan 31 '13 at 07:07
  • When a real question is posted, I'll write a real answer. For the time being, this is as far as I'm willing to go. The OP will have to demonstrate _some_ research effort before I consider doing more work for him, and you should do the same! This answer contains more than enough information for the OP to find his solution. – Lightness Races in Orbit Jan 31 '13 at 07:07
  • Okay, so lets say I want the quantity of an item, and i can see it's [quantity] => 1. How do I output this? – Emerson F Jan 31 '13 at 07:16
  • By the way, I'm willing to do more research, but being said that, I can't research more on it as this is not my forte. I looked around for 2 hours to find some examples but can't find any – Emerson F Jan 31 '13 at 07:18
  • @EmersonF: The code you have now generates some output. What is it? Go from there. – Lightness Races in Orbit Jan 31 '13 at 07:20
  • Look at my question above again. Just added it in – Emerson F Jan 31 '13 at 07:28
  • @EmersonF: It would have been nice if you could format it properly, so that it's legible. Anyway, now you have a map of the object `$invoice`, which has some URL members that I can see, and you can set about learning how to interpret that output to reach your final solution. – Lightness Races in Orbit Jan 31 '13 at 07:31
  • Am I supposed to write a script to find the keyword and output what I want? I'm really sorry for being a newbie, looking at the downvotes I get. – Emerson F Jan 31 '13 at 07:49
0

Invoice is an instane of a class. You should treat it like all instances.

To get URL value you can do the next:

<?php
$invoice_id=118868;

$invoice=$freshbooks->invoiceGet($invoice_id);
print $invoice->url;
?>

or there's another possible value you're looking for:

<?php
$invoice_id=118868;

$invoice=$freshbooks->invoiceGet($invoice_id);
print $invoice->links->client_view;
?>

According to official API doc <url> is not supporting any more, so you should use <links> "element to provide your customers with direct links to the invoice for editing, viewing by the client and viewing by an administrator."

KennyPowers
  • 4,925
  • 8
  • 36
  • 51
  • Thanks! That's the kind of ans I was looking for, however, still doesn't work. I tried echo, but my page is still blank.. – Emerson F Jan 31 '13 at 14:44
  • Seems you got an error. Add `ini_set('display_errors','1');` in the start of your script -- this will help you to see the errors if they're there. – KennyPowers Jan 31 '13 at 15:58