Unable to create a contact

Hi Ben,

You should wrap all those parameters inside a contact key like

{“contact”: {“organisation_name”: “test”} }

Hope this helps,
Mihai

Mihai Anca — Ruby developer
http://www.freeagent.com (http://www.freeagent.com/)

Voted Best SME Accounting Software in the UK
Follow us on Twitter: @freeagentOn Tuesday, 14 August 2012 at 12:02, Ben Mason wrote:

I am posting the following to https://api.freeagent.com/v2/contacts:

{“organisation_name”: “Test Organisation”}

(the headers are in and working fine, Accept, Content-Type and Auth)

I get the following back:

{“errors”:[{“message”:“first_name can’t be blank”},{“message”:“last_name can’t be blank”},{“message”:“organisation_name can’t be blank”}]}

I don’t understand this.

Any help would be most appreciated.

Ben


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/-/1C6avdnxNJ8J.
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.

I am encoding my array using json_encode(), in php, and posting by using
curl, getting the response in json array and decoding it, but not setting
the header application header as application/json
because the library default put the header in the end.On Monday, 30 December 2013 15:33:56 UTC+5:30, Jonathan Barrett wrote:

Hi there,

Looking at the logs here, your request is being escaped as it’s being sent
through. Are you specifying that the query is in JSON when sending the
request?

-J

hi jonathan,
$this is a object of class which i am using to set token and token type,

and $contact_arr is a json array as shown below:

{“contact”:{“first_name”:“Vipul”,“last_name”:“Kumar”,“organisation_name”:“Smart Inventory",“email”:"vipul.kumar@amvrin.com”,“phone_number”:“201301”,“address1”:“dfdcsaFSd”,“town”:“fdsfdsf”,“postcode”:“0”,“country”:“India”,“created_at”:“2013-12-31T10:07:50+00:00”}}

Thanks

hi jonathan,

Can u look at this issue of contact adding, I think code is going
correctly, still i m experimenting with the code.

Please help in that case

thanks
Vipul

hi jonathan,

I am using code from this library,

I have customize this and add some methods to this class, I am using client
class, and using fetch function from client class

thanks for replyOn Tuesday, 31 December 2013 16:07:42 UTC+5:30, Jonathan Barrett wrote:

So $this is a class you’ve written? What’s the implementation of fetch
on that object, and how are you assigning $contact_arr? Is it just a
string?

-J

On Tue, Dec 31, 2013 at 10:25 AM, vipul Kumar <dashin...@gmail.com<javascript:> wrote:

hi jonathan,
$this is a object of class which i am using to set token and token type,

and $contact_arr is a json array as shown below:

{“contact”:{“first_name”:“Vipul”,“last_name”:“Kumar”,“organisation_name”:“Smart Inventory",“email”:"vipul.kumar@amvrin.com <javascript:>”,“phone_number”:“201301”,“address1”:“dfdcsaFSd”,“town”:“fdsfdsf”,“postcode”:“0”,“country”:“India”,“created_at”:“2013-12-31T10:07:50+00:00”}}

Thanks


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to freeagent_ap...@googlegroups.com <javascript:>.
To post to this group, send email to freeag...@googlegroups.com<javascript:>
.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.

Jonathan Barrett, Senior Engineer

FreeAgent: Accounting software, simplified
www.freeagent.com

+44 (0)131 447 0011

Follow us on Twitter: @freeagent https://twitter.com/freeagent

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

Thanks Vipul,

Looking at the request in our logs, I’m suspecting that your JSON array is
being converted to a string by the fetch method, and being escaped.
What’s $this in your example? Have you tried specifying $contact_arr as
a PHP array instead?

-JOn Tue, Dec 31, 2013 at 10:12 AM, vipul Kumar dashing.vipul@gmail.comwrote:

Thanks for quick reply jonathan,

Can u give a fast example of array we have to send in json form,
Currently I am using this code and json data array,

{“contact”:{“first_name”:“Vipul”,“last_name”:“Kumar”,“organisation_name”:“Smart Inventory",“email”:"vipul.kumar@amvrin.com”,“phone_number”:“201301”,“address1”:“dfdcsaFSd”,“town”:“fdsfdsf”,“postcode”:“0”,“country”:“India”,“created_at”:“2013-12-31T10:07:50+00:00”}}

$response = $this->fetch(
$base_url . ‘/contacts’, //API path
$contact_arr, //request parameters
parent::HTTP_METHOD_POST, //GET, PUT, POST, DELETE
array(‘User-Agent’ => ‘Smart Inventory’, ‘Accept’ =>
‘application/json’)
);

Please notify that, Am I in a right direction?
thanks,


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to freeagent_api+unsubscribe@googlegroups.com.
To post to this group, send email to freeagent_api@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.

Jonathan Barrett, Senior Engineer

FreeAgent: Accounting software, simplified

+44 (0)131 447 0011

Follow us on Twitter: @freeagent https://twitter.com/freeagent

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

Hi All,

I am also getting the same error,

either I am sending the array in json format,

{“contact”:{“first_name”:“Vipul”,“last_name”:“Kumar”,“email”:“vipul.kumar@amvrin.com”,“phone_number”:“201301”,“address1”:“dfdcsaFSd”,“town”:“fdsfdsf”,“postcode”:“0”,“country”:“India”}}
or in PHP Format,

[contact] => Array
(
[first_name] => Vipul
[last_name] => Kumar
[email] => vipul.kumar@amvrin.com
[phone_number] => 201301
[address1] => dfdcsaFSd
[town] => fdsfdsf
[postcode] => 0
[country] => India
)

Hi there,

Looking at the logs here, your request is being escaped as it’s being sent
through. Are you specifying that the query is in JSON when sending the
request?

-J

Thanks for quick reply jonathan,

Can u give a fast example of array we have to send in json form,
Currently I am using this code and json data array,

{“contact”:{“first_name”:“Vipul”,“last_name”:“Kumar”,“organisation_name”:“Smart Inventory",“email”:"vipul.kumar@amvrin.com”,“phone_number”:“201301”,“address1”:“dfdcsaFSd”,“town”:“fdsfdsf”,“postcode”:“0”,“country”:“India”,“created_at”:“2013-12-31T10:07:50+00:00”}}

$response = $this->fetch(
$base_url . ‘/contacts’, //API path
$contact_arr, //request parameters
parent::HTTP_METHOD_POST, //GET, PUT, POST, DELETE
array(‘User-Agent’ => ‘Smart Inventory’, ‘Accept’ =>
‘application/json’)
);

Please notify that, Am I in a right direction?
thanks,

Hi Vipul,

The request is still coming through escaped, I’m afraid, and without being
identified as application/json.

I can’t promise to help you debug your PHP code, but if you post an example
of what you’re using, I (or someone else in the group) might be able to
spot something obvious.

Cheers,

-JOn Tue, Dec 31, 2013 at 8:49 AM, vipul Kumar dashing.vipul@gmail.comwrote:

hi jonathan,

Can u look at this issue of contact adding, I think code is going
correctly, still i m experimenting with the code.

Please help in that case

thanks
Vipul


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to freeagent_api+unsubscribe@googlegroups.com.
To post to this group, send email to freeagent_api@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.

Jonathan Barrett, Senior Engineer

FreeAgent: Accounting software, simplified

+44 (0)131 447 0011

Follow us on Twitter: @freeagent https://twitter.com/freeagent

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

Thanks for reply Jonathan,
Wishing a very Happy new Year to all guys in group.

I had resolved this problem,
Thanks for shown me the server array,
I just try to pass an extra parameter in header

‘Accept’ => ‘application/json’,
‘Content-type’=> ‘application/json’

and It works,
Thanks once again!On Tuesday, 31 December 2013 17:00:19 UTC+5:30, Jonathan Barrett wrote:

Hi Vipul,

It looks to me like the handling of the POST parameters differs depending
on whether $contact_arr is an array or not. Can you show me how you’re
assigning that value before handing it into fetch? I know you keep saying
“it’s JSON”, but I’m not sure if you mean it’s a JSON-formatted string or
if it’s being natively handled by PHP in a JSON object.

Cheers,

-J

So $this is a class you’ve written? What’s the implementation of fetch
on that object, and how are you assigning $contact_arr? Is it just a
string?

-JOn Tue, Dec 31, 2013 at 10:25 AM, vipul Kumar dashing.vipul@gmail.comwrote:

hi jonathan,
$this is a object of class which i am using to set token and token type,

and $contact_arr is a json array as shown below:

{“contact”:{“first_name”:“Vipul”,“last_name”:“Kumar”,“organisation_name”:“Smart Inventory",“email”:"vipul.kumar@amvrin.com”,“phone_number”:“201301”,“address1”:“dfdcsaFSd”,“town”:“fdsfdsf”,“postcode”:“0”,“country”:“India”,“created_at”:“2013-12-31T10:07:50+00:00”}}

Thanks


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to freeagent_api+unsubscribe@googlegroups.com.
To post to this group, send email to freeagent_api@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.

Jonathan Barrett, Senior Engineer

FreeAgent: Accounting software, simplified

+44 (0)131 447 0011

Follow us on Twitter: @freeagent https://twitter.com/freeagent

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

Hi Vipul,

It looks to me like the handling of the POST parameters differs depending
on whether $contact_arr is an array or not. Can you show me how you’re
assigning that value before handing it into fetch? I know you keep saying
“it’s JSON”, but I’m not sure if you mean it’s a JSON-formatted string or
if it’s being natively handled by PHP in a JSON object.

Cheers,

-J