Creating new invoice via API

Hi Ben,

I’m not sure what’s going wrong for you. The following works for me:

curl -H “Authorization: Bearer XXXXX” -H “Accept: application/xml” -H
“Content-type: application/json” api.lvh.me:3000/v2/invoices -X POST
-d ‘{
“invoice”:{
“reference”:XX46,
“contact”:“https://api.freeagent.com/v2/contacts/XXX”,
“status”:“Sent”,
“dated_on”:“2012-10-16T00:00:00+00:00”,
“due_on”:“2012-10-30T00:00:00+00:00”,
“payment_terms_in_days”:14,
“invoice_items”:[
{
“item_type”:“Services”,
“price”:“600.00”,
“description”:“XXXXXXXXX (30/10/2012 - 29/11/2012)”
}
]
}
}’

The “Resource not found” message is usually displayed if you’re
hitting the wrong API path. Can you double check you’re hitting
https://api.freeagent.com/v2/invoices?

Kind regards,

GraemeOn 18 October 2012 03:11, Ben Harris ben@primexeon.com wrote:

Hi All,

I keep getting the response “Resource not found” when posting the following
to https://api.freeagent.com/v2/invoices

Can anyone see where I’m going wrong?

Cheers

Ben

{
“invoice”:{
“reference”:XX46,
“contact”:“https://api.freeagent.com/v2/contacts/XXXXX79”,
“status”:“Sent”,
“dated_on”:“2012-10-16T00:00:00+00:00”,
“due_on”:“2012-10-30T00:00:00+00:00”,
“payment_terms_in_days”:14,
“invoice_items”:[
{
“item_type”:“Services”,
“price”:“600.00”,
“description”:“XXXXXXXXX (30/10/2012 - 29/11/2012)”
}
]
}
}


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/freeagent_api/-/GzODM6IrD0cJ.
To post to this group, send email to freeagent_api@googlegroups.com.
To unsubscribe from this group, send email to
freeagent_api+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/freeagent_api?hl=en.

Graeme Boyd
Senior Software Engineer

Web. freeagent.com Blog. freeagent.com/blog
Twitter. @freeagent Facebook. facebook.com/freeagentapp

40 Torphichen Street, Edinburgh, EH3 8JB
FreeAgent Central Ltd. Registered in sunny Scotland SC316774

I just typecasted them to string, and I’m still getting the same problem.
This is my output now:

{
“invoice”:{
“reference”:“3546”,
“contact”:“https://api.freeagent.com/v2/contacts/1189979”,
“status”:“Sent”,
“dated_on”:“2012-10-16T00:00:00+00:00”,
“due_on”:“2012-10-30T00:00:00+00:00”,
“payment_terms_in_days”:“14”,
“invoice_items”:[
{
“item_type”:“Services”,
“price”:“600.00”,
“description”:
“Brigantia Contract - brigantia.com (30/10/2012 - 29/11/2012)”
}
]
}
}

I’m still getting the same problem?On Thursday, October 18, 2012 3:09:44 PM UTC+1, Nic Wise wrote:

Reference may need "'s around it - it’s a string, not an int.

On Thu, Oct 18, 2012 at 2:55 PM, Ben Harris <b...@primexeon.com<javascript:>> wrote:

Hi Graeme,

I’m pretty sure I am hitting the correct API path as if I put some
invalid
params in, it says something like “dated_on” not set, and payment terms
in
days not valid.

This is my code:
$addinvoice = $client->fetch(
$base_url . ‘/invoices’, //API path
array( ‘invoice’ =>
array( ‘reference’ => $invoice_id,
‘contact’ => $fa_user_url,
‘status’ => ‘Sent’,
‘dated_on’ =>
$invoice_date.“T00:00:00+00:00”,
‘due_on’ =>
$invoice_due.“T00:00:00+00:00”,
‘payment_terms_in_days’ =>
(int)(floor((strtotime($invoice_due) - strtotime($invoice_date)) / (60 *
60

  • 24))),
    ‘invoice_items’ => $invoice_items
    )
    ), //request parameters
    OAuth2\Client::HTTP_METHOD_POST, //GET, PUT, POST,
    DELETE
    array(‘User-Agent’ => ‘XXXXXXXXX WHMCS Hook’) //API
    requires
    UA header
    );

I’m using the php OAuth2 lib

Cheers

Ben

On Thursday, October 18, 2012 2:42:24 PM UTC+1, Graeme Boyd wrote:

Hi Ben,

I’m not sure what’s going wrong for you. The following works for me:

curl -H “Authorization: Bearer XXXXX” -H “Accept: application/xml” -H
“Content-type: application/json” api.lvh.me:3000/v2/invoices -X POST
-d ‘{
“invoice”:{
“reference”:XX46,
“contact”:“https://api.freeagent.com/v2/contacts/XXX”,
“status”:“Sent”,
“dated_on”:“2012-10-16T00:00:00+00:00”,
“due_on”:“2012-10-30T00:00:00+00:00”,
“payment_terms_in_days”:14,
“invoice_items”:[
{
“item_type”:“Services”,
“price”:“600.00”,
“description”:“XXXXXXXXX (30/10/2012 - 29/11/2012)”
}
]
}
}’

The “Resource not found” message is usually displayed if you’re
hitting the wrong API path. Can you double check you’re hitting
https://api.freeagent.com/v2/invoices?

Kind regards,

Graeme

On 18 October 2012 03:11, Ben Harris b...@primexeon.com wrote:

Hi All,

I keep getting the response “Resource not found” when posting the
following
to https://api.freeagent.com/v2/invoices

Can anyone see where I’m going wrong?

Cheers

Ben

{
“invoice”:{
“reference”:XX46,
“contact”:“https://api.freeagent.com/v2/contacts/XXXXX79”,

  "status":"Sent", 
  "dated_on":"2012-10-16T00:00:00+00:00", 
  "due_on":"2012-10-30T00:00:00+00:00", 
  "payment_terms_in_days":14, 
  "invoice_items":[ 
     { 
        "item_type":"Services", 
        "price":"600.00", 
        "description":"XXXXXXXXX (30\/10\/2012 - 29\/11\/2012)" 
     } 
  ] 

}
}


You received this message because you are subscribed to the Google
Groups
“FreeAgent API” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/freeagent_api/-/GzODM6IrD0cJ.
To post to this group, send email to freeag...@googlegroups.com.
To unsubscribe from this group, send email to
freeagent_ap...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/freeagent_api?hl=en.


Graeme Boyd
Senior Software Engineer

Web. freeagent.com Blog. freeagent.com/blog
Twitter. @freeagent Facebook. facebook.com/freeagentapp

40 Torphichen Street, Edinburgh, EH3 8JB
FreeAgent Central Ltd. Registered in sunny Scotland SC316774


You received this message because you are subscribed to the Google
Groups
“FreeAgent API” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/freeagent_api/-/MmY_5k78xUEJ.

To post to this group, send email to freeag...@googlegroups.com<javascript:>.

To unsubscribe from this group, send email to
freeagent_ap...@googlegroups.com <javascript:>.
For more options, visit this group at
http://groups.google.com/group/freeagent_api?hl=en.


Nic Wise
t. +44 7788 592 806 | @fastchicken | http://www.linkedin.com/in/nicwise
b. http://www.fastchicken.co.nz/

mobileAgent (for FreeAgent): get your accounts in your pocket.
http://goo.gl/IuBU
Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
Earnest: Self-employed? Track your business expenses and income.
http://earnestapp.com
Nearest Bus: find when the next bus is coming to your stop.
http://goo.gl/Vcz1p
London Bike App: Find the nearest Boris Bike, and get riding!
http://goo.gl/Icp2

Hi Ben,

This line:

$base_url . ‘/invoices’, //API path

Should it be:

$base_url . ‘/v2/invoices’, //API path

I suggest you dump the JSON your PHP code generates to disk and use
the curl command I linked in my first email to test it out.

Kind regards,

GraemeOn 18 October 2012 15:33, Ben Harris ben@primexeon.com wrote:

I just typecasted them to string, and I’m still getting the same problem.
This is my output now:

{
“invoice”:{
“reference”:“3546”,
“contact”:“https://api.freeagent.com/v2/contacts/1189979”,

  "status":"Sent",
  "dated_on":"2012-10-16T00:00:00+00:00",
  "due_on":"2012-10-30T00:00:00+00:00",
  "payment_terms_in_days":"14",
  "invoice_items":[
     {
        "item_type":"Services",
        "price":"600.00",
        "description":"Brigantia Contract - brigantia.com (30\/10\/2012
  • 29/11/2012)"
    }
    ]
    }
    }

I’m still getting the same problem?

On Thursday, October 18, 2012 3:09:44 PM UTC+1, Nic Wise wrote:

Reference may need "'s around it - it’s a string, not an int.

On Thu, Oct 18, 2012 at 2:55 PM, Ben Harris b...@primexeon.com wrote:

Hi Graeme,

I’m pretty sure I am hitting the correct API path as if I put some
invalid
params in, it says something like “dated_on” not set, and payment terms
in
days not valid.

This is my code:
$addinvoice = $client->fetch(
$base_url . ‘/invoices’, //API path
array( ‘invoice’ =>
array( ‘reference’ => $invoice_id,
‘contact’ => $fa_user_url,
‘status’ => ‘Sent’,
‘dated_on’ =>
$invoice_date.“T00:00:00+00:00”,
‘due_on’ =>
$invoice_due.“T00:00:00+00:00”,
‘payment_terms_in_days’ =>
(int)(floor((strtotime($invoice_due) - strtotime($invoice_date)) / (60 *
60

  • 24))),
    ‘invoice_items’ => $invoice_items
    )
    ), //request parameters
    OAuth2\Client::HTTP_METHOD_POST, //GET, PUT, POST,
    DELETE
    array(‘User-Agent’ => ‘XXXXXXXXX WHMCS Hook’) //API
    requires
    UA header
    );

I’m using the php OAuth2 lib

Cheers

Ben

On Thursday, October 18, 2012 2:42:24 PM UTC+1, Graeme Boyd wrote:

Hi Ben,

I’m not sure what’s going wrong for you. The following works for me:

curl -H “Authorization: Bearer XXXXX” -H “Accept: application/xml” -H
“Content-type: application/json” api.lvh.me:3000/v2/invoices -X POST
-d ‘{
“invoice”:{
“reference”:XX46,
“contact”:“https://api.freeagent.com/v2/contacts/XXX”,
“status”:“Sent”,
“dated_on”:“2012-10-16T00:00:00+00:00”,
“due_on”:“2012-10-30T00:00:00+00:00”,
“payment_terms_in_days”:14,
“invoice_items”:[
{
“item_type”:“Services”,
“price”:“600.00”,
“description”:“XXXXXXXXX (30/10/2012 - 29/11/2012)”
}
]
}
}’

The “Resource not found” message is usually displayed if you’re
hitting the wrong API path. Can you double check you’re hitting
https://api.freeagent.com/v2/invoices?

Kind regards,

Graeme

On 18 October 2012 03:11, Ben Harris b...@primexeon.com wrote:

Hi All,

I keep getting the response “Resource not found” when posting the
following
to https://api.freeagent.com/v2/invoices

Can anyone see where I’m going wrong?

Cheers

Ben

{
“invoice”:{
“reference”:XX46,
“contact”:“https://api.freeagent.com/v2/contacts/XXXXX79”,
“status”:“Sent”,
“dated_on”:“2012-10-16T00:00:00+00:00”,
“due_on”:“2012-10-30T00:00:00+00:00”,
“payment_terms_in_days”:14,
“invoice_items”:[
{
“item_type”:“Services”,
“price”:“600.00”,
“description”:“XXXXXXXXX (30/10/2012 - 29/11/2012)”
}
]
}
}


You received this message because you are subscribed to the Google
Groups
“FreeAgent API” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/freeagent_api/-/GzODM6IrD0cJ.
To post to this group, send email to freeag...@googlegroups.com.
To unsubscribe from this group, send email to
freeagent_ap...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/freeagent_api?hl=en.


Graeme Boyd
Senior Software Engineer

Web. freeagent.com Blog. freeagent.com/blog
Twitter. @freeagent Facebook. facebook.com/freeagentapp

40 Torphichen Street, Edinburgh, EH3 8JB
FreeAgent Central Ltd. Registered in sunny Scotland SC316774


You received this message because you are subscribed to the Google
Groups
“FreeAgent API” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/freeagent_api/-/MmY_5k78xUEJ.

To post to this group, send email to freeag...@googlegroups.com.
To unsubscribe from this group, send email to
freeagent_ap...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/freeagent_api?hl=en.


Nic Wise
t. +44 7788 592 806 | @fastchicken | http://www.linkedin.com/in/nicwise
b. http://www.fastchicken.co.nz/

mobileAgent (for FreeAgent): get your accounts in your pocket.
http://goo.gl/IuBU
Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
Earnest: Self-employed? Track your business expenses and income.
http://earnestapp.com
Nearest Bus: find when the next bus is coming to your stop.
http://goo.gl/Vcz1p
London Bike App: Find the nearest Boris Bike, and get riding!
http://goo.gl/Icp2


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/freeagent_api/-/U4uYHKsHzLAJ.

To post to this group, send email to freeagent_api@googlegroups.com.
To unsubscribe from this group, send email to
freeagent_api+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/freeagent_api?hl=en.

Graeme Boyd
Senior Software Engineer

Web. freeagent.com Blog. freeagent.com/blog
Twitter. @freeagent Facebook. facebook.com/freeagentapp

40 Torphichen Street, Edinburgh, EH3 8JB
FreeAgent Central Ltd. Registered in sunny Scotland SC316774

Hi Graeme,

I’m pretty sure I am hitting the correct API path as if I put some invalid
params in, it says something like “dated_on” not set, and payment terms in
days not valid.

This is my code:
$addinvoice = $client->fetch(
$base_url . ‘/invoices’, //API path
array( ‘invoice’ =>
array( ‘reference’ => $invoice_id,
‘contact’ => $fa_user_url,
‘status’ => ‘Sent’,
‘dated_on’ =>
$invoice_date.“T00:00:00+00:00”,
‘due_on’ =>
$invoice_due.“T00:00:00+00:00”,
‘payment_terms_in_days’ =>
(int)(floor((strtotime($invoice_due) - strtotime($invoice_date)) / (60 * 60

  • 24))),
    ‘invoice_items’ => $invoice_items
    )
    ), //request parameters
    OAuth2\Client::HTTP_METHOD_POST, //GET, PUT, POST, DELETE
    array(‘User-Agent’ => ‘XXXXXXXXX WHMCS Hook’) //API
    requires UA header
    );

I’m using the php OAuth2 lib

Cheers

BenOn Thursday, October 18, 2012 2:42:24 PM UTC+1, Graeme Boyd wrote:

Hi Ben,

I’m not sure what’s going wrong for you. The following works for me:

curl -H “Authorization: Bearer XXXXX” -H “Accept: application/xml” -H
“Content-type: application/json” api.lvh.me:3000/v2/invoices -X POST
-d ‘{
“invoice”:{
“reference”:XX46,
“contact”:“https://api.freeagent.com/v2/contacts/XXX”,
“status”:“Sent”,
“dated_on”:“2012-10-16T00:00:00+00:00”,
“due_on”:“2012-10-30T00:00:00+00:00”,
“payment_terms_in_days”:14,
“invoice_items”:[
{
“item_type”:“Services”,
“price”:“600.00”,
“description”:“XXXXXXXXX (30/10/2012 - 29/11/2012)”
}
]
}
}’

The “Resource not found” message is usually displayed if you’re
hitting the wrong API path. Can you double check you’re hitting
https://api.freeagent.com/v2/invoices?

Kind regards,

Graeme

On 18 October 2012 03:11, Ben Harris <b...@primexeon.com <javascript:>> wrote:

Hi All,

I keep getting the response “Resource not found” when posting the
following
to https://api.freeagent.com/v2/invoices

Can anyone see where I’m going wrong?

Cheers

Ben

{
“invoice”:{
“reference”:XX46,
“contact”:“https://api.freeagent.com/v2/contacts/XXXXX79”,
“status”:“Sent”,
“dated_on”:“2012-10-16T00:00:00+00:00”,
“due_on”:“2012-10-30T00:00:00+00:00”,
“payment_terms_in_days”:14,
“invoice_items”:[
{
“item_type”:“Services”,
“price”:“600.00”,
“description”:“XXXXXXXXX (30/10/2012 - 29/11/2012)”
}
]
}
}


You received this message because you are subscribed to the Google
Groups
“FreeAgent API” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/freeagent_api/-/GzODM6IrD0cJ.
To post to this group, send email to freeag...@googlegroups.com<javascript:>.

To unsubscribe from this group, send email to
freeagent_ap...@googlegroups.com <javascript:>.
For more options, visit this group at
http://groups.google.com/group/freeagent_api?hl=en.


Graeme Boyd
Senior Software Engineer

Web. freeagent.com Blog. freeagent.com/blog
Twitter. @freeagent Facebook. facebook.com/freeagentapp

40 Torphichen Street, Edinburgh, EH3 8JB
FreeAgent Central Ltd. Registered in sunny Scotland SC316774

Hi Graeme,

My base url includes the v2 bit.

Running it from curl worked, but I still can’t see where the issue is. I’m
successfully getting all clients, and recent invoices. Just having an issue
pushing one.

BenOn Thursday, October 18, 2012 5:27:33 PM UTC+1, Graeme Boyd wrote:

Hi Ben,

This line:

$base_url . ‘/invoices’, //API path

Should it be:

$base_url . ‘/v2/invoices’, //API path

I suggest you dump the JSON your PHP code generates to disk and use
the curl command I linked in my first email to test it out.

Kind regards,

Graeme

On 18 October 2012 15:33, Ben Harris <b...@primexeon.com <javascript:>> wrote:

I just typecasted them to string, and I’m still getting the same
problem.
This is my output now:

{
“invoice”:{
“reference”:“3546”,
“contact”:“https://api.freeagent.com/v2/contacts/1189979”,

  "status":"Sent", 
  "dated_on":"2012-10-16T00:00:00+00:00", 
  "due_on":"2012-10-30T00:00:00+00:00", 
  "payment_terms_in_days":"14", 
  "invoice_items":[ 
     { 
        "item_type":"Services", 
        "price":"600.00", 
        "description":"Brigantia Contract - brigantia.com(30\/10\/2012 
  • 29/11/2012)"
    }
    ]
    }
    }

I’m still getting the same problem?

On Thursday, October 18, 2012 3:09:44 PM UTC+1, Nic Wise wrote:

Reference may need "'s around it - it’s a string, not an int.

On Thu, Oct 18, 2012 at 2:55 PM, Ben Harris b...@primexeon.com wrote:

Hi Graeme,

I’m pretty sure I am hitting the correct API path as if I put some
invalid
params in, it says something like “dated_on” not set, and payment
terms

in
days not valid.

This is my code:
$addinvoice = $client->fetch(
$base_url . ‘/invoices’, //API path
array( ‘invoice’ =>
array( ‘reference’ => $invoice_id,
‘contact’ =>
$fa_user_url,

                           'status'                  => 'Sent', 
                           'dated_on'             => 

$invoice_date.“T00:00:00+00:00”,
‘due_on’ =>
$invoice_due.“T00:00:00+00:00”,
‘payment_terms_in_days’ =>
(int)(floor((strtotime($invoice_due) - strtotime($invoice_date)) /
(60 *

60

  • 24))),
    ‘invoice_items’ =>
    $invoice_items
                    ) 
            ), //request parameters 
            OAuth2\Client::HTTP_METHOD_POST, //GET, PUT, POST, 

DELETE
array(‘User-Agent’ => ‘XXXXXXXXX WHMCS Hook’) //API
requires
UA header
);

I’m using the php OAuth2 lib

Cheers

Ben

On Thursday, October 18, 2012 2:42:24 PM UTC+1, Graeme Boyd wrote:

Hi Ben,

I’m not sure what’s going wrong for you. The following works for
me:

curl -H “Authorization: Bearer XXXXX” -H “Accept: application/xml”
-H

“Content-type: application/json” api.lvh.me:3000/v2/invoices -X
POST

-d ‘{
“invoice”:{
“reference”:XX46,
“contact”:“https://api.freeagent.com/v2/contacts/XXX”,
“status”:“Sent”,
“dated_on”:“2012-10-16T00:00:00+00:00”,
“due_on”:“2012-10-30T00:00:00+00:00”,
“payment_terms_in_days”:14,
“invoice_items”:[
{
“item_type”:“Services”,
“price”:“600.00”,
“description”:“XXXXXXXXX (30/10/2012 - 29/11/2012)”
}
]
}
}’

The “Resource not found” message is usually displayed if you’re
hitting the wrong API path. Can you double check you’re hitting
https://api.freeagent.com/v2/invoices?

Kind regards,

Graeme

On 18 October 2012 03:11, Ben Harris b...@primexeon.com wrote:

Hi All,

I keep getting the response “Resource not found” when posting the
following
to https://api.freeagent.com/v2/invoices

Can anyone see where I’m going wrong?

Cheers

Ben

{
“invoice”:{
“reference”:XX46,
“contact”:“https://api.freeagent.com/v2/contacts/XXXXX79”,

  "status":"Sent", 
  "dated_on":"2012-10-16T00:00:00+00:00", 
  "due_on":"2012-10-30T00:00:00+00:00", 
  "payment_terms_in_days":14, 
  "invoice_items":[ 
     { 
        "item_type":"Services", 
        "price":"600.00", 
        "description":"XXXXXXXXX (30\/10\/2012 - 

29/11/2012)"

     } 
  ] 

}
}


You received this message because you are subscribed to the Google
Groups
“FreeAgent API” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/freeagent_api/-/GzODM6IrD0cJ.
To post to this group, send email to freeag...@googlegroups.com.
To unsubscribe from this group, send email to
freeagent_ap...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/freeagent_api?hl=en.


Graeme Boyd
Senior Software Engineer

Web. freeagent.com Blog. freeagent.com/blog
Twitter. @freeagent Facebook. facebook.com/freeagentapp

40 Torphichen Street, Edinburgh, EH3 8JB
FreeAgent Central Ltd. Registered in sunny Scotland SC316774


You received this message because you are subscribed to the Google
Groups
“FreeAgent API” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/freeagent_api/-/MmY_5k78xUEJ.

To post to this group, send email to freeag...@googlegroups.com.
To unsubscribe from this group, send email to
freeagent_ap...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/freeagent_api?hl=en.


Nic Wise
t. +44 7788 592 806 | @fastchicken |
http://www.linkedin.com/in/nicwise

b. http://www.fastchicken.co.nz/

mobileAgent (for FreeAgent): get your accounts in your pocket.
http://goo.gl/IuBU
Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
Earnest: Self-employed? Track your business expenses and income.
http://earnestapp.com
Nearest Bus: find when the next bus is coming to your stop.
http://goo.gl/Vcz1p
London Bike App: Find the nearest Boris Bike, and get riding!
http://goo.gl/Icp2


You received this message because you are subscribed to the Google
Groups
“FreeAgent API” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/freeagent_api/-/U4uYHKsHzLAJ.

To post to this group, send email to freeag...@googlegroups.com<javascript:>.

To unsubscribe from this group, send email to
freeagent_ap...@googlegroups.com <javascript:>.
For more options, visit this group at
http://groups.google.com/group/freeagent_api?hl=en.


Graeme Boyd
Senior Software Engineer

Web. freeagent.com Blog. freeagent.com/blog
Twitter. @freeagent Facebook. facebook.com/freeagentapp

40 Torphichen Street, Edinburgh, EH3 8JB
FreeAgent Central Ltd. Registered in sunny Scotland SC316774

Reference may need "'s around it - it’s a string, not an int.On Thu, Oct 18, 2012 at 2:55 PM, Ben Harris ben@primexeon.com wrote:

Hi Graeme,

I’m pretty sure I am hitting the correct API path as if I put some invalid
params in, it says something like “dated_on” not set, and payment terms in
days not valid.

This is my code:
$addinvoice = $client->fetch(
$base_url . ‘/invoices’, //API path
array( ‘invoice’ =>
array( ‘reference’ => $invoice_id,
‘contact’ => $fa_user_url,
‘status’ => ‘Sent’,
‘dated_on’ =>
$invoice_date.“T00:00:00+00:00”,
‘due_on’ =>
$invoice_due.“T00:00:00+00:00”,
‘payment_terms_in_days’ =>
(int)(floor((strtotime($invoice_due) - strtotime($invoice_date)) / (60 * 60

  • 24))),
    ‘invoice_items’ => $invoice_items
    )
    ), //request parameters
    OAuth2\Client::HTTP_METHOD_POST, //GET, PUT, POST, DELETE
    array(‘User-Agent’ => ‘XXXXXXXXX WHMCS Hook’) //API requires
    UA header
    );

I’m using the php OAuth2 lib

Cheers

Ben

On Thursday, October 18, 2012 2:42:24 PM UTC+1, Graeme Boyd wrote:

Hi Ben,

I’m not sure what’s going wrong for you. The following works for me:

curl -H “Authorization: Bearer XXXXX” -H “Accept: application/xml” -H
“Content-type: application/json” api.lvh.me:3000/v2/invoices -X POST
-d ‘{
“invoice”:{
“reference”:XX46,
“contact”:“https://api.freeagent.com/v2/contacts/XXX”,
“status”:“Sent”,
“dated_on”:“2012-10-16T00:00:00+00:00”,
“due_on”:“2012-10-30T00:00:00+00:00”,
“payment_terms_in_days”:14,
“invoice_items”:[
{
“item_type”:“Services”,
“price”:“600.00”,
“description”:“XXXXXXXXX (30/10/2012 - 29/11/2012)”
}
]
}
}’

The “Resource not found” message is usually displayed if you’re
hitting the wrong API path. Can you double check you’re hitting
https://api.freeagent.com/v2/invoices?

Kind regards,

Graeme

On 18 October 2012 03:11, Ben Harris b...@primexeon.com wrote:

Hi All,

I keep getting the response “Resource not found” when posting the
following
to https://api.freeagent.com/v2/invoices

Can anyone see where I’m going wrong?

Cheers

Ben

{
“invoice”:{
“reference”:XX46,
“contact”:“https://api.freeagent.com/v2/contacts/XXXXX79”,
“status”:“Sent”,
“dated_on”:“2012-10-16T00:00:00+00:00”,
“due_on”:“2012-10-30T00:00:00+00:00”,
“payment_terms_in_days”:14,
“invoice_items”:[
{
“item_type”:“Services”,
“price”:“600.00”,
“description”:“XXXXXXXXX (30/10/2012 - 29/11/2012)”
}
]
}
}


You received this message because you are subscribed to the Google
Groups
“FreeAgent API” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/freeagent_api/-/GzODM6IrD0cJ.
To post to this group, send email to freeag...@googlegroups.com.
To unsubscribe from this group, send email to
freeagent_ap...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/freeagent_api?hl=en.


Graeme Boyd
Senior Software Engineer

Web. freeagent.com Blog. freeagent.com/blog
Twitter. @freeagent Facebook. facebook.com/freeagentapp

40 Torphichen Street, Edinburgh, EH3 8JB
FreeAgent Central Ltd. Registered in sunny Scotland SC316774


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/freeagent_api/-/MmY_5k78xUEJ.

To post to this group, send email to freeagent_api@googlegroups.com.
To unsubscribe from this group, send email to
freeagent_api+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/freeagent_api?hl=en.

Nic Wise
t. +44 7788 592 806 | @fastchicken | http://www.linkedin.com/in/nicwise
b. http://www.fastchicken.co.nz/

mobileAgent (for FreeAgent): get your accounts in your pocket.
http://goo.gl/IuBU
Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
Earnest: Self-employed? Track your business expenses and income.
http://earnestapp.com
Nearest Bus: find when the next bus is coming to your stop. http://goo.gl/Vcz1p
London Bike App: Find the nearest Boris Bike, and get riding! http://goo.gl/Icp2

Has anyone else had similar problems with PHP OAuth 2 + FA/RESTful APIs?On Thursday, October 18, 2012 6:27:20 PM UTC+1, Ben Harris wrote:

Hi Graeme,

My base url includes the v2 bit.

Running it from curl worked, but I still can’t see where the issue is. I’m
successfully getting all clients, and recent invoices. Just having an issue
pushing one.

Ben

On Thursday, October 18, 2012 5:27:33 PM UTC+1, Graeme Boyd wrote:

Hi Ben,

This line:

$base_url . ‘/invoices’, //API path

Should it be:

$base_url . ‘/v2/invoices’, //API path

I suggest you dump the JSON your PHP code generates to disk and use
the curl command I linked in my first email to test it out.

Kind regards,

Graeme

On 18 October 2012 15:33, Ben Harris b...@primexeon.com wrote:

I just typecasted them to string, and I’m still getting the same
problem.
This is my output now:

{
“invoice”:{
“reference”:“3546”,
“contact”:“https://api.freeagent.com/v2/contacts/1189979”,

  "status":"Sent", 
  "dated_on":"2012-10-16T00:00:00+00:00", 
  "due_on":"2012-10-30T00:00:00+00:00", 
  "payment_terms_in_days":"14", 
  "invoice_items":[ 
     { 
        "item_type":"Services", 
        "price":"600.00", 
        "description":"Brigantia Contract - brigantia.com(30\/10\/2012 
  • 29/11/2012)"
    }
    ]
    }
    }

I’m still getting the same problem?

On Thursday, October 18, 2012 3:09:44 PM UTC+1, Nic Wise wrote:

Reference may need "'s around it - it’s a string, not an int.

On Thu, Oct 18, 2012 at 2:55 PM, Ben Harris b...@primexeon.com wrote:

Hi Graeme,

I’m pretty sure I am hitting the correct API path as if I put some
invalid
params in, it says something like “dated_on” not set, and payment
terms

in
days not valid.

This is my code:
$addinvoice = $client->fetch(
$base_url . ‘/invoices’, //API path
array( ‘invoice’ =>
array( ‘reference’ => $invoice_id,
‘contact’ =>
$fa_user_url,

                           'status'                  => 'Sent', 
                           'dated_on'             => 

$invoice_date.“T00:00:00+00:00”,
‘due_on’ =>
$invoice_due.“T00:00:00+00:00”,
‘payment_terms_in_days’ =>
(int)(floor((strtotime($invoice_due) - strtotime($invoice_date)) /
(60 *

60

  • 24))),
    ‘invoice_items’ =>
    $invoice_items
                    ) 
            ), //request parameters 
            OAuth2\Client::HTTP_METHOD_POST, //GET, PUT, POST, 

DELETE
array(‘User-Agent’ => ‘XXXXXXXXX WHMCS Hook’) //API
requires
UA header
);

I’m using the php OAuth2 lib

Cheers

Ben

On Thursday, October 18, 2012 2:42:24 PM UTC+1, Graeme Boyd wrote:

Hi Ben,

I’m not sure what’s going wrong for you. The following works for
me:

curl -H “Authorization: Bearer XXXXX” -H “Accept: application/xml”
-H

“Content-type: application/json” api.lvh.me:3000/v2/invoices -X
POST

-d ‘{
“invoice”:{
“reference”:XX46,
“contact”:“https://api.freeagent.com/v2/contacts/XXX”,
“status”:“Sent”,
“dated_on”:“2012-10-16T00:00:00+00:00”,
“due_on”:“2012-10-30T00:00:00+00:00”,
“payment_terms_in_days”:14,
“invoice_items”:[
{
“item_type”:“Services”,
“price”:“600.00”,
“description”:“XXXXXXXXX (30/10/2012 - 29/11/2012)”
}
]
}
}’

The “Resource not found” message is usually displayed if you’re
hitting the wrong API path. Can you double check you’re hitting
https://api.freeagent.com/v2/invoices?

Kind regards,

Graeme

On 18 October 2012 03:11, Ben Harris b...@primexeon.com wrote:

Hi All,

I keep getting the response “Resource not found” when posting the
following
to https://api.freeagent.com/v2/invoices

Can anyone see where I’m going wrong?

Cheers

Ben

{
“invoice”:{
“reference”:XX46,
“contact”:“https://api.freeagent.com/v2/contacts/XXXXX79”,

  "status":"Sent", 
  "dated_on":"2012-10-16T00:00:00+00:00", 
  "due_on":"2012-10-30T00:00:00+00:00", 
  "payment_terms_in_days":14, 
  "invoice_items":[ 
     { 
        "item_type":"Services", 
        "price":"600.00", 
        "description":"XXXXXXXXX (30\/10\/2012 - 

29/11/2012)"

     } 
  ] 

}
}


You received this message because you are subscribed to the
Google

Groups
“FreeAgent API” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/freeagent_api/-/GzODM6IrD0cJ.
To post to this group, send email to freeag...@googlegroups.com.
To unsubscribe from this group, send email to
freeagent_ap...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/freeagent_api?hl=en.


Graeme Boyd
Senior Software Engineer

Web. freeagent.com Blog. freeagent.com/blog
Twitter. @freeagent Facebook. facebook.com/freeagentapp

40 Torphichen Street, Edinburgh, EH3 8JB
FreeAgent Central Ltd. Registered in sunny Scotland SC316774


You received this message because you are subscribed to the Google
Groups
“FreeAgent API” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/freeagent_api/-/MmY_5k78xUEJ.

To post to this group, send email to freeag...@googlegroups.com.
To unsubscribe from this group, send email to
freeagent_ap...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/freeagent_api?hl=en.


Nic Wise
t. +44 7788 592 806 | @fastchicken |
http://www.linkedin.com/in/nicwise

b. http://www.fastchicken.co.nz/

mobileAgent (for FreeAgent): get your accounts in your pocket.
http://goo.gl/IuBU
Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
Earnest: Self-employed? Track your business expenses and income.
http://earnestapp.com
Nearest Bus: find when the next bus is coming to your stop.
http://goo.gl/Vcz1p
London Bike App: Find the nearest Boris Bike, and get riding!
http://goo.gl/Icp2


You received this message because you are subscribed to the Google
Groups
“FreeAgent API” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/freeagent_api/-/U4uYHKsHzLAJ.

To post to this group, send email to freeag...@googlegroups.com.
To unsubscribe from this group, send email to
freeagent_ap...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/freeagent_api?hl=en.


Graeme Boyd
Senior Software Engineer

Web. freeagent.com Blog. freeagent.com/blog
Twitter. @freeagent Facebook. facebook.com/freeagentapp

40 Torphichen Street, Edinburgh, EH3 8JB
FreeAgent Central Ltd. Registered in sunny Scotland SC316774