Create Project through API - PHP cURL

Please humour / help me, as I’ve been banging my head against a brick wall
for the last hour on what has to be a really stupid, obvious thing.

I can:

  • Send a user to FreeAgent to authenticate using oAuth 2
  • Receive an authorization code, and make a request to get access and
    refresh tokens
  • Send a GET request e.g. get all projects

$c = curl_init(‘https://api.sandbox.freeagent.com/v2/projects’);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
‘Accept: application/json’,
‘Content-Type: application/json’,
'Authorization: Bearer '.$accessToken
));
curl_setopt($c, CURLOPT_USERAGENT, ‘n7 Studios’);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, false);
// Get response from server
$response = curl_exec($c);
$body = json_decode($response);
curl_close($c);

What I cannot for the life of me do is create a project through the API:

$params = array(
‘contact’ => ‘837040’,
‘name’ => ‘Test Project’,
‘starts_on’ => ‘2012-05-11’,
‘ends_on’ => ‘2012-05-18’,
‘budget’ => ‘280’,
‘status’ => ‘Active’,
‘budget_units’ => ‘Monetary’,
‘normal_billing_rate’ => ‘10’,
‘hours_per_day’ => ‘8’,
‘currency’ => ‘GBP’
);

$c = curl_init(‘https://api.sandbox.freeagent.com/v2/projects’);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
‘Accept: application/json’,
‘Content-Type: application/json’,
'Authorization: Bearer '.$accessToken
));
curl_setopt($c, CURLOPT_USERAGENT, ‘n7 Studios’);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($params));

The result I get is that all fields are empty:

stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[message] => contact can’t be blank
)

        [1] => stdClass Object
            (
                [message] => name can't be blank
            )

        [2] => stdClass Object
            (
                [message] => status can't be blank,is invalid
            )

        [3] => stdClass Object
            (
                [message] => status can't be blank,is invalid
            )

        [4] => stdClass Object
            (
                [message] => currency is not an accepted currency
            )

        [5] => stdClass Object
            (
                [message] => budget_units is invalid
            )
    )

)

I’ve been through the Documentation about 5 times, and whilst it gives examples of how to perform GET requests, there’s nothing for POST requests.

What am I missing that’s so obvious please?

What is it MENT to be?

I’d assume /contacts/1234

?

But then, I’d also assume I get those BACK if I request a project, but
I get a fully qualified URL (https://sandbox.api…/v2/contacts/1234)On Mon, May 21, 2012 at 11:50 AM, Ryan Stenhouse ryan@freeagent.com wrote:

Hi everyone,

Looks like this might be a bug, really sorry about that!

We’re still looking into this, and I’ll update as soon as I have more
information.

Thanks for your patience!

Best wishes,

Ryan Stenhouse
Ruby Engineer

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

SOFTWARE SATISFACTION AWARDS 2012 - Vote for us (We’d be super stoked!)

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

On Saturday, 19 May 2012 at 14:59, Nic Wise wrote:

Hi Everyone

I’m trying to do the same. If I GET a project, I get back a contact of

“contact”:“https://api.sandbox.freeagent.com/v2/contacts/167

if I make a new project, and POST it, I get the same resource issue.
I’ve tried it with:

“contact”:“https://api.sandbox.freeagent.com/v2/contacts/167
“contact”:"/v2/contacts/167"
“contact”:"/contacts/167"

None of them work. Any ideas?

Full posted JSON below:

{“project”:{“contact”:"/v2/contacts/167",“name”:“project
TEST”,“starts_on”:null,“ends_on”:null,“budget”:0,“is_ir35”:false,“contract_po_reference”:null,“status”:“Active”,“budget_units”:“Days”,“normal_billing_rate”:0,“hours_per_day”:0,“uses_project_invoice_sequence”:false,“currency”:“GBP”,“billing_period”:null,“url”:"",“updated_at”:"",“created_at”:""}}

Thanks!

BTW, /contacts/167 exists (in bttest.sandbox) as the previous call, I
GET it then use that to make the new project.

Ta

On Tue, May 15, 2012 at 2:48 PM, Olly H olly@freeagent.com wrote:

Hi Tim

It seems to me that the contact value is wrong. Shouldn’t it be a path as
per:

'contact' => '/contacts/837040'

Cheers,
Olly

On Tuesday, May 15, 2012 2:41:46 PM UTC+1, Tim Carr wrote:

Hi Mihai,

I’ve tried that using the below code, but still no luck:

$params = array(
‘project’ => array(
‘contact’ => ‘837040’,
‘name’ => ‘Test Project’,
‘starts_on’ => ‘2012-05-11’,
‘ends_on’ => ‘2012-05-18’,
‘budget’ => ‘280’,
‘status’ => ‘Active’,
‘budget_units’ => ‘Monetary’,
‘normal_billing_rate’ => ‘10’,
‘hours_per_day’ => ‘8’,
‘currency’ => ‘GBP’
)
);

$c = curl_init(‘https://api.sandbox.freeagent.com/v2/projects’);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
‘Accept: application/json’,
‘Content-Type: application/json’,
'Authorization: Bearer '.$accessToken
));
curl_setopt($c, CURLOPT_USERAGENT, ‘n7 Studios’);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($params));

I still receive the same errors as before.

Thanks,

Tim.


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/-/Iy3-n7Btle8J.

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/

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
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
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 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.


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
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/

Earnest: Self-employed? Track your business expenses and income.


Nearest Bus: find when the next bus is coming to your stop. http://goo.gl/Vcz1p
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
London Bike App: Find the nearest Boris Bike, and get riding! http://goo.gl/Icp2

Hi Everyone

I’m trying to do the same. If I GET a project, I get back a contact of

“contact”:“https://api.sandbox.freeagent.com/v2/contacts/167

if I make a new project, and POST it, I get the same resource issue.
I’ve tried it with:

“contact”:“https://api.sandbox.freeagent.com/v2/contacts/167
“contact”:"/v2/contacts/167"
“contact”:"/contacts/167"

None of them work. Any ideas?

Full posted JSON below:

{“project”:{“contact”:"/v2/contacts/167",“name”:“project
TEST”,“starts_on”:null,“ends_on”:null,“budget”:0,“is_ir35”:false,“contract_po_reference”:null,“status”:“Active”,“budget_units”:“Days”,“normal_billing_rate”:0,“hours_per_day”:0,“uses_project_invoice_sequence”:false,“currency”:“GBP”,“billing_period”:null,“url”:"",“updated_at”:"",“created_at”:""}}

Thanks!

BTW, /contacts/167 exists (in bttest.sandbox) as the previous call, I
GET it then use that to make the new project.

TaOn Tue, May 15, 2012 at 2:48 PM, Olly H olly@freeagent.com wrote:

Hi Tim

It seems to me that the contact value is wrong. Shouldn’t it be a path as
per:

'contact' => '/contacts/837040'

Cheers,
Olly

On Tuesday, May 15, 2012 2:41:46 PM UTC+1, Tim Carr wrote:

Hi Mihai,

I’ve tried that using the below code, but still no luck:

$params = array(
‘project’ => array(
‘contact’ => ‘837040’,
‘name’ => ‘Test Project’,
‘starts_on’ => ‘2012-05-11’,
‘ends_on’ => ‘2012-05-18’,
‘budget’ => ‘280’,
‘status’ => ‘Active’,
‘budget_units’ => ‘Monetary’,
‘normal_billing_rate’ => ‘10’,
‘hours_per_day’ => ‘8’,
‘currency’ => ‘GBP’
)
);

$c = curl_init(‘https://api.sandbox.freeagent.com/v2/projects’);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
‘Accept: application/json’,
‘Content-Type: application/json’,
'Authorization: Bearer '.$accessToken
));
curl_setopt($c, CURLOPT_USERAGENT, ‘n7 Studios’);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($params));

I still receive the same errors as before.

Thanks,

Tim.


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/-/Iy3-n7Btle8J.

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/

Earnest: Self-employed? Track your business expenses and income.


Nearest Bus: find when the next bus is coming to your stop. http://goo.gl/Vcz1p
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
London Bike App: Find the nearest Boris Bike, and get riding! http://goo.gl/Icp2

Actually, when I run the below code (with ‘project’ being the key,
comprising of an array of key/value pairs), I receive a 404 error:

stdClass Object
(
[errors] => stdClass Object
(
[error] => stdClass Object
(
[message] => Resource not found
)

    )

)On Tuesday, 15 May 2012 14:41:46 UTC+1, Tim Carr wrote:

Hi Mihai,

I’ve tried that using the below code, but still no luck:

$params = array(
‘project’ => array(
‘contact’ => ‘837040’,
‘name’ => ‘Test Project’,
‘starts_on’ => ‘2012-05-11’,
‘ends_on’ => ‘2012-05-18’,
‘budget’ => ‘280’,
‘status’ => ‘Active’,
‘budget_units’ => ‘Monetary’,
‘normal_billing_rate’ => ‘10’,
‘hours_per_day’ => ‘8’,
‘currency’ => ‘GBP’
)
);

$c = curl_init(‘https://api.sandbox.freeagent.com/v2/projects’);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
‘Accept: application/json’,
‘Content-Type: application/json’,
'Authorization: Bearer '.$accessToken
));
curl_setopt($c, CURLOPT_USERAGENT, ‘n7 Studios’);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($params));

I still receive the same errors as before.

Thanks,

Tim.

On Sunday, 13 May 2012 22:19:40 UTC+1, Mihai Anca wrote:

Hi Tim,

Sorry for not being clear. I think the main problem is that you should
wrap all those attributes in an “project” tag.

Can you try something like:

$params = array(‘project’ => array(all params));

Let me if this works.
Mihai


Mihai Anca
Software Engineer
FreeAgent Central Ltd
40 Torphichen Street, Edinburgh EH3 8JB
Registered in Scotland SC316774

On Sunday, May 13, 2012 9:59:06 PM UTC+1, Tim Carr wrote:

Please humour / help me, as I’ve been banging my head against a brick
wall for the last hour on what has to be a really stupid, obvious
thing.

I can:

  • Send a user to FreeAgent to authenticate using oAuth 2
  • Receive an authorization code, and make a request to get access
    and refresh tokens
  • Send a GET request e.g. get all projects

$c = curl_init(‘https://api.sandbox.freeagent.com/v2/projects’);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
‘Accept: application/json’,
‘Content-Type: application/json’,
'Authorization: Bearer '.$accessToken
));
curl_setopt($c, CURLOPT_USERAGENT, ‘n7 Studios’);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, false);
// Get response from server
$response = curl_exec($c);
$body = json_decode($response);
curl_close($c);

What I cannot for the life of me do is create a project through the API:

$params = array(
‘contact’ => ‘837040’,
‘name’ => ‘Test Project’,
‘starts_on’ => ‘2012-05-11’,
‘ends_on’ => ‘2012-05-18’,
‘budget’ => ‘280’,
‘status’ => ‘Active’,
‘budget_units’ => ‘Monetary’,
‘normal_billing_rate’ => ‘10’,
‘hours_per_day’ => ‘8’,
‘currency’ => ‘GBP’
);

$c = curl_init(‘https://api.sandbox.freeagent.com/v2/projects’);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
‘Accept: application/json’,
‘Content-Type: application/json’,
'Authorization: Bearer '.$accessToken
));
curl_setopt($c, CURLOPT_USERAGENT, ‘n7 Studios’);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($params));

The result I get is that all fields are empty:

stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[message] => contact can’t be blank
)

        [1] => stdClass Object
            (
                [message] => name can't be blank
            )

        [2] => stdClass Object
            (
                [message] => status can't be blank,is invalid
            )

        [3] => stdClass Object
            (
                [message] => status can't be blank,is invalid
            )

        [4] => stdClass Object
            (
                [message] => currency is not an accepted currency
            )

        [5] => stdClass Object
            (
                [message] => budget_units is invalid
            )
    )

)

I’ve been through the Documentation about 5 times, and whilst it gives examples of how to perform GET requests, there’s nothing for POST requests.

What am I missing that’s so obvious please?

On Sunday, May 13, 2012 9:59:06 PM UTC+1, Tim Carr wrote:

Please humour / help me, as I’ve been banging my head against a brick
wall for the last hour on what has to be a really stupid, obvious
thing.

I can:

  • Send a user to FreeAgent to authenticate using oAuth 2
  • Receive an authorization code, and make a request to get access
    and refresh tokens
  • Send a GET request e.g. get all projects

$c = curl_init(‘https://api.sandbox.freeagent.com/v2/projects’);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
‘Accept: application/json’,
‘Content-Type: application/json’,
'Authorization: Bearer '.$accessToken
));
curl_setopt($c, CURLOPT_USERAGENT, ‘n7 Studios’);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, false);
// Get response from server
$response = curl_exec($c);
$body = json_decode($response);
curl_close($c);

What I cannot for the life of me do is create a project through the API:

$params = array(
‘contact’ => ‘837040’,
‘name’ => ‘Test Project’,
‘starts_on’ => ‘2012-05-11’,
‘ends_on’ => ‘2012-05-18’,
‘budget’ => ‘280’,
‘status’ => ‘Active’,
‘budget_units’ => ‘Monetary’,
‘normal_billing_rate’ => ‘10’,
‘hours_per_day’ => ‘8’,
‘currency’ => ‘GBP’
);

$c = curl_init(‘https://api.sandbox.freeagent.com/v2/projects’);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
‘Accept: application/json’,
‘Content-Type: application/json’,
'Authorization: Bearer '.$accessToken
));
curl_setopt($c, CURLOPT_USERAGENT, ‘n7 Studios’);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($params));

The result I get is that all fields are empty:

stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[message] => contact can’t be blank
)

        [1] => stdClass Object
            (
                [message] => name can't be blank
            )

        [2] => stdClass Object
            (
                [message] => status can't be blank,is invalid
            )

        [3] => stdClass Object
            (
                [message] => status can't be blank,is invalid
            )

        [4] => stdClass Object
            (
                [message] => currency is not an accepted currency
            )

        [5] => stdClass Object
            (
                [message] => budget_units is invalid
            )
    )

)

I’ve been through the Documentation about 5 times, and whilst it gives examples of how to perform GET requests, there’s nothing for POST requests.

What am I missing that’s so obvious please?

Thanks Olly, creating projects is now working for me.

Have a good weekend.

Tim.On Tuesday, 22 May 2012 00:04:36 UTC+1, Olly H wrote:

Hey Nic

The docs are right - contact should be specified with a path:
/v2/contacts/1234. However, as Ryan mentions there is a bug. Or there was

  • I’ve just pushed a fix (to both sandbox and production) which should make
    this work for you.

Sorry for the trouble :-/

Olly

On Monday, May 21, 2012 1:19:47 PM UTC+1, Nic Wise wrote:

What is it MENT to be?

I’d assume /contacts/1234

?

But then, I’d also assume I get those BACK if I request a project, but
I get a fully qualified URL (https://sandbox.api…/v2/contacts/1234)

Hey Nic

The docs are right - contact should be specified with a path:
/v2/contacts/1234. However, as Ryan mentions there is a bug. Or there was

  • I’ve just pushed a fix (to both sandbox and production) which should make
    this work for you.

Sorry for the trouble :-/

OllyOn Monday, May 21, 2012 1:19:47 PM UTC+1, Nic Wise wrote:

What is it MENT to be?

I’d assume /contacts/1234

?

But then, I’d also assume I get those BACK if I request a project, but
I get a fully qualified URL (https://sandbox.api…/v2/contacts/1234)

Hi Tim,

Sorry for not being clear. I think the main problem is that you should wrap
all those attributes in an “project” tag.

Can you try something like:

$params = array(‘project’ => array(all params));

Let me if this works.
Mihai

Mihai Anca
Software Engineer
FreeAgent Central Ltd
40 Torphichen Street, Edinburgh EH3 8JB
Registered in Scotland SC316774On Sunday, May 13, 2012 9:59:06 PM UTC+1, Tim Carr wrote:

Please humour / help me, as I’ve been banging my head against a brick wall
for the last hour on what has to be a really stupid, obvious thing.

I can:

  • Send a user to FreeAgent to authenticate using oAuth 2
  • Receive an authorization code, and make a request to get access and
    refresh tokens
  • Send a GET request e.g. get all projects

$c = curl_init(‘https://api.sandbox.freeagent.com/v2/projects’);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
‘Accept: application/json’,
‘Content-Type: application/json’,
'Authorization: Bearer '.$accessToken
));
curl_setopt($c, CURLOPT_USERAGENT, ‘n7 Studios’);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, false);
// Get response from server
$response = curl_exec($c);
$body = json_decode($response);
curl_close($c);

What I cannot for the life of me do is create a project through the API:

$params = array(
‘contact’ => ‘837040’,
‘name’ => ‘Test Project’,
‘starts_on’ => ‘2012-05-11’,
‘ends_on’ => ‘2012-05-18’,
‘budget’ => ‘280’,
‘status’ => ‘Active’,
‘budget_units’ => ‘Monetary’,
‘normal_billing_rate’ => ‘10’,
‘hours_per_day’ => ‘8’,
‘currency’ => ‘GBP’
);

$c = curl_init(‘https://api.sandbox.freeagent.com/v2/projects’);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
‘Accept: application/json’,
‘Content-Type: application/json’,
'Authorization: Bearer '.$accessToken
));
curl_setopt($c, CURLOPT_USERAGENT, ‘n7 Studios’);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($params));

The result I get is that all fields are empty:

stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[message] => contact can’t be blank
)

        [1] => stdClass Object
            (
                [message] => name can't be blank
            )

        [2] => stdClass Object
            (
                [message] => status can't be blank,is invalid
            )

        [3] => stdClass Object
            (
                [message] => status can't be blank,is invalid
            )

        [4] => stdClass Object
            (
                [message] => currency is not an accepted currency
            )

        [5] => stdClass Object
            (
                [message] => budget_units is invalid
            )
    )

)

I’ve been through the Documentation about 5 times, and whilst it gives examples of how to perform GET requests, there’s nothing for POST requests.

What am I missing that’s so obvious please?

On Sunday, May 13, 2012 9:59:06 PM UTC+1, Tim Carr wrote:

Please humour / help me, as I’ve been banging my head against a brick wall
for the last hour on what has to be a really stupid, obvious thing.

I can:

  • Send a user to FreeAgent to authenticate using oAuth 2
  • Receive an authorization code, and make a request to get access and
    refresh tokens
  • Send a GET request e.g. get all projects

$c = curl_init(‘https://api.sandbox.freeagent.com/v2/projects’);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
‘Accept: application/json’,
‘Content-Type: application/json’,
'Authorization: Bearer '.$accessToken
));
curl_setopt($c, CURLOPT_USERAGENT, ‘n7 Studios’);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, false);
// Get response from server
$response = curl_exec($c);
$body = json_decode($response);
curl_close($c);

What I cannot for the life of me do is create a project through the API:

$params = array(
‘contact’ => ‘837040’,
‘name’ => ‘Test Project’,
‘starts_on’ => ‘2012-05-11’,
‘ends_on’ => ‘2012-05-18’,
‘budget’ => ‘280’,
‘status’ => ‘Active’,
‘budget_units’ => ‘Monetary’,
‘normal_billing_rate’ => ‘10’,
‘hours_per_day’ => ‘8’,
‘currency’ => ‘GBP’
);

$c = curl_init(‘https://api.sandbox.freeagent.com/v2/projects’);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
‘Accept: application/json’,
‘Content-Type: application/json’,
'Authorization: Bearer '.$accessToken
));
curl_setopt($c, CURLOPT_USERAGENT, ‘n7 Studios’);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($params));

The result I get is that all fields are empty:

stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[message] => contact can’t be blank
)

        [1] => stdClass Object
            (
                [message] => name can't be blank
            )

        [2] => stdClass Object
            (
                [message] => status can't be blank,is invalid
            )

        [3] => stdClass Object
            (
                [message] => status can't be blank,is invalid
            )

        [4] => stdClass Object
            (
                [message] => currency is not an accepted currency
            )

        [5] => stdClass Object
            (
                [message] => budget_units is invalid
            )
    )

)

I’ve been through the Documentation about 5 times, and whilst it gives examples of how to perform GET requests, there’s nothing for POST requests.

What am I missing that’s so obvious please?

Hi Tim

It seems to me that the contact value is wrong. Shouldn’t it be a path as
per:

'contact' => '/contacts/837040'

Cheers,
OllyOn Tuesday, May 15, 2012 2:41:46 PM UTC+1, Tim Carr wrote:

Hi Mihai,

I’ve tried that using the below code, but still no luck:

$params = array(
‘project’ => array(
‘contact’ => ‘837040’,
‘name’ => ‘Test Project’,
‘starts_on’ => ‘2012-05-11’,
‘ends_on’ => ‘2012-05-18’,
‘budget’ => ‘280’,
‘status’ => ‘Active’,
‘budget_units’ => ‘Monetary’,
‘normal_billing_rate’ => ‘10’,
‘hours_per_day’ => ‘8’,
‘currency’ => ‘GBP’
)
);

$c = curl_init(‘https://api.sandbox.freeagent.com/v2/projects’);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
‘Accept: application/json’,
‘Content-Type: application/json’,
'Authorization: Bearer '.$accessToken
));
curl_setopt($c, CURLOPT_USERAGENT, ‘n7 Studios’);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($params));

I still receive the same errors as before.

Thanks,

Tim.

Hi everyone,

Looks like this might be a bug, really sorry about that!

We’re still looking into this, and I’ll update as soon as I have more information.

Thanks for your patience!

Best wishes,

Ryan Stenhouse
Ruby Engineer

Web. freeagent.com (http://www.freeagent.com/)
Blog. freeagent.com/blog (http://freeagent.com/blog)

Twitter. @freeagent (https://twitter.com/#!/freeagent)
Facebook. facebook.com/freeagentapp (http://facebook.com/freeagentapp)

SOFTWARE SATISFACTION AWARDS 2012 - Vote for us (http://www.clicktools.com/survey?iv=1c8dgs13zfxs7r&q1=FreeAgent%20Central%20Ltd&q2=FreeAgent&q3=Accounting%20and%20Finance) (We’d be super stoked!)

40 Torphichen Street, Edinburgh, EH3 8JB
FreeAgent Central Ltd. Registered in sunny Scotland SC316774On Saturday, 19 May 2012 at 14:59, Nic Wise wrote:

Hi Everyone

I’m trying to do the same. If I GET a project, I get back a contact of

“contact”:“https://api.sandbox.freeagent.com/v2/contacts/167

if I make a new project, and POST it, I get the same resource issue.
I’ve tried it with:

“contact”:“https://api.sandbox.freeagent.com/v2/contacts/167
“contact”:"/v2/contacts/167"
“contact”:"/contacts/167"

None of them work. Any ideas?

Full posted JSON below:

{“project”:{“contact”:"/v2/contacts/167",“name”:“project
TEST”,“starts_on”:null,“ends_on”:null,“budget”:0,“is_ir35”:false,“contract_po_reference”:null,“status”:“Active”,“budget_units”:“Days”,“normal_billing_rate”:0,“hours_per_day”:0,“uses_project_invoice_sequence”:false,“currency”:“GBP”,“billing_period”:null,“url”:"",“updated_at”:"",“created_at”:""}}

Thanks!

BTW, /contacts/167 exists (in bttest.sandbox) as the previous call, I
GET it then use that to make the new project.

Ta

On Tue, May 15, 2012 at 2:48 PM, Olly H <olly@freeagent.com (mailto:olly@freeagent.com)> wrote:

Hi Tim

It seems to me that the contact value is wrong. Shouldn’t it be a path as
per:

'contact' => '/contacts/837040'

Cheers,
Olly

On Tuesday, May 15, 2012 2:41:46 PM UTC+1, Tim Carr wrote:

Hi Mihai,

I’ve tried that using the below code, but still no luck:

$params = array(
‘project’ => array(
‘contact’ => ‘837040’,
‘name’ => ‘Test Project’,
‘starts_on’ => ‘2012-05-11’,
‘ends_on’ => ‘2012-05-18’,
‘budget’ => ‘280’,
‘status’ => ‘Active’,
‘budget_units’ => ‘Monetary’,
‘normal_billing_rate’ => ‘10’,
‘hours_per_day’ => ‘8’,
‘currency’ => ‘GBP’
)
);

$c = curl_init(‘https://api.sandbox.freeagent.com/v2/projects’);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
‘Accept: application/json’,
‘Content-Type: application/json’,
'Authorization: Bearer '.$accessToken
));
curl_setopt($c, CURLOPT_USERAGENT, ‘n7 Studios’);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($params));

I still receive the same errors as before.

Thanks,

Tim.

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/-/Iy3-n7Btle8J.

To post to this group, send email to freeagent_api@googlegroups.com (mailto:freeagent_api@googlegroups.com).
To unsubscribe from this group, send email to
freeagent_api+unsubscribe@googlegroups.com (mailto: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/

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
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
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 post to this group, send email to freeagent_api@googlegroups.com (mailto:freeagent_api@googlegroups.com).
To unsubscribe from this group, send email to freeagent_api+unsubscribe@googlegroups.com (mailto:freeagent_api+unsubscribe@googlegroups.com).
For more options, visit this group at http://groups.google.com/group/freeagent_api?hl=en.

Hi Mihai,

I’ve tried that using the below code, but still no luck:

$params = array(
‘project’ => array(
‘contact’ => ‘837040’,
‘name’ => ‘Test Project’,
‘starts_on’ => ‘2012-05-11’,
‘ends_on’ => ‘2012-05-18’,
‘budget’ => ‘280’,
‘status’ => ‘Active’,
‘budget_units’ => ‘Monetary’,
‘normal_billing_rate’ => ‘10’,
‘hours_per_day’ => ‘8’,
‘currency’ => ‘GBP’
)
);

$c = curl_init(‘https://api.sandbox.freeagent.com/v2/projects’);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
‘Accept: application/json’,
‘Content-Type: application/json’,
'Authorization: Bearer '.$accessToken
));
curl_setopt($c, CURLOPT_USERAGENT, ‘n7 Studios’);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($params));

I still receive the same errors as before.

Thanks,

Tim.On Sunday, 13 May 2012 22:19:40 UTC+1, Mihai Anca wrote:

Hi Tim,

Sorry for not being clear. I think the main problem is that you should
wrap all those attributes in an “project” tag.

Can you try something like:

$params = array(‘project’ => array(all params));

Let me if this works.
Mihai


Mihai Anca
Software Engineer
FreeAgent Central Ltd
40 Torphichen Street, Edinburgh EH3 8JB
Registered in Scotland SC316774

On Sunday, May 13, 2012 9:59:06 PM UTC+1, Tim Carr wrote:

Please humour / help me, as I’ve been banging my head against a brick
wall for the last hour on what has to be a really stupid, obvious
thing.

I can:

  • Send a user to FreeAgent to authenticate using oAuth 2
  • Receive an authorization code, and make a request to get access and
    refresh tokens
  • Send a GET request e.g. get all projects

$c = curl_init(‘https://api.sandbox.freeagent.com/v2/projects’);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
‘Accept: application/json’,
‘Content-Type: application/json’,
'Authorization: Bearer '.$accessToken
));
curl_setopt($c, CURLOPT_USERAGENT, ‘n7 Studios’);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, false);
// Get response from server
$response = curl_exec($c);
$body = json_decode($response);
curl_close($c);

What I cannot for the life of me do is create a project through the API:

$params = array(
‘contact’ => ‘837040’,
‘name’ => ‘Test Project’,
‘starts_on’ => ‘2012-05-11’,
‘ends_on’ => ‘2012-05-18’,
‘budget’ => ‘280’,
‘status’ => ‘Active’,
‘budget_units’ => ‘Monetary’,
‘normal_billing_rate’ => ‘10’,
‘hours_per_day’ => ‘8’,
‘currency’ => ‘GBP’
);

$c = curl_init(‘https://api.sandbox.freeagent.com/v2/projects’);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
‘Accept: application/json’,
‘Content-Type: application/json’,
'Authorization: Bearer '.$accessToken
));
curl_setopt($c, CURLOPT_USERAGENT, ‘n7 Studios’);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($params));

The result I get is that all fields are empty:

stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[message] => contact can’t be blank
)

        [1] => stdClass Object
            (
                [message] => name can't be blank
            )

        [2] => stdClass Object
            (
                [message] => status can't be blank,is invalid
            )

        [3] => stdClass Object
            (
                [message] => status can't be blank,is invalid
            )

        [4] => stdClass Object
            (
                [message] => currency is not an accepted currency
            )

        [5] => stdClass Object
            (
                [message] => budget_units is invalid
            )
    )

)

I’ve been through the Documentation about 5 times, and whilst it gives examples of how to perform GET requests, there’s nothing for POST requests.

What am I missing that’s so obvious please?

On Sunday, May 13, 2012 9:59:06 PM UTC+1, Tim Carr wrote:

Please humour / help me, as I’ve been banging my head against a brick
wall for the last hour on what has to be a really stupid, obvious
thing.

I can:

  • Send a user to FreeAgent to authenticate using oAuth 2
  • Receive an authorization code, and make a request to get access and
    refresh tokens
  • Send a GET request e.g. get all projects

$c = curl_init(‘https://api.sandbox.freeagent.com/v2/projects’);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
‘Accept: application/json’,
‘Content-Type: application/json’,
'Authorization: Bearer '.$accessToken
));
curl_setopt($c, CURLOPT_USERAGENT, ‘n7 Studios’);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, false);
// Get response from server
$response = curl_exec($c);
$body = json_decode($response);
curl_close($c);

What I cannot for the life of me do is create a project through the API:

$params = array(
‘contact’ => ‘837040’,
‘name’ => ‘Test Project’,
‘starts_on’ => ‘2012-05-11’,
‘ends_on’ => ‘2012-05-18’,
‘budget’ => ‘280’,
‘status’ => ‘Active’,
‘budget_units’ => ‘Monetary’,
‘normal_billing_rate’ => ‘10’,
‘hours_per_day’ => ‘8’,
‘currency’ => ‘GBP’
);

$c = curl_init(‘https://api.sandbox.freeagent.com/v2/projects’);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
‘Accept: application/json’,
‘Content-Type: application/json’,
'Authorization: Bearer '.$accessToken
));
curl_setopt($c, CURLOPT_USERAGENT, ‘n7 Studios’);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($params));

The result I get is that all fields are empty:

stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[message] => contact can’t be blank
)

        [1] => stdClass Object
            (
                [message] => name can't be blank
            )

        [2] => stdClass Object
            (
                [message] => status can't be blank,is invalid
            )

        [3] => stdClass Object
            (
                [message] => status can't be blank,is invalid
            )

        [4] => stdClass Object
            (
                [message] => currency is not an accepted currency
            )

        [5] => stdClass Object
            (
                [message] => budget_units is invalid
            )
    )

)

I’ve been through the Documentation about 5 times, and whilst it gives examples of how to perform GET requests, there’s nothing for POST requests.

What am I missing that’s so obvious please?