API3
slater at April 3rd, 2014 05:44 — #1
I've having some troubles figuring out how a request to the v3 of the API would look like to update a contacts custom fields.
I'm not sure how the JSON data should be formated/structured/serialized.
Can you provide an example?
pete_onepagecrm at April 3rd, 2014 05:53 — #2
Hi slater
Here are two samples file which are actually recorded network transmission between a small API client and one of our development servers. You'll find there how requested JSON data should look like as well as any other required fields (like request headers).
You'll find more information about fields which you can set & update here: http://www.onepagecrm.com/api/v3/contacts.html
Hope this helps.
Creating a contact:
POST /api/v3/contacts.json HTTP/1.1
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept: */*
User-Agent: Ruby
Content-Type: application/json; charset=utf-8
X-Onepagecrm-Uid: 513dbfd85230503122000001
X-Onepagecrm-Ts: 1393596809
X-Onepagecrm-Auth: eb0da61bd33503059ed6956cc78b5ec8c30ec9322ed97c5e66cc51cf72a906f6
Host: app.onepagecrm.com
Content-Length: 300
{"first_name":"Johny","last_name":"Bravo","company_name":"API Inc.","tags":["tag1","tag2","tag3"],"starred":true,"custom_fields":[{"id":"522aec5952305004af000002","value":"Single line Custom Field"},{"id":"522aec3b52305004c9000001","value":13},{"id":"513dbfdc523050312200008f","value":"2014-08-03"}]}
HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Status: 201 Created
X-OnePageCRM-BuildID: 13540:e15c756d80f9
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
X-Frame-Options: SAMEORIGIN
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: X-OnePageCRM-UID
Access-Control-Allow-Headers: X-OnePageCRM-TS
Access-Control-Allow-Headers: X-OnePageCRM-Auth
Access-Control-Allow-Headers: Content-Type
X-UA-Compatible: IE=Edge
X-Request-Id: 8f1776aad6053f2edef5f1597eb522fc
X-Runtime: 0.117955
X-Powered-By: Phusion Passenger xxx
Date: Fri, 28 Feb 2014 14:13:29 GMT
Server: nginx/xxx + Phusion Passenger xxx
{"status":0,"message":"Created","timestamp":1393596809,"data":{"contact":{"id":"531099895230504785000014","owner_id":"513dbfd85230503122000001","first_name":"Johny","last_name":"Bravo","job_title":"","description":"","urls":[],"phones":[],"emails":[],"status_id":"5224ae9552305011c000000b","starred":true,"lead_source_id":"","company_type":true,"company_name":"API Inc.","company_id":"531099895230504785000015","tags":["tag1","tag2","tag3"],"custom_fields":[{"custom_field":{"id":"522aec5952305004af000002","name":"Single line","type":"single_line_text"},"value":"Single line Custom Field"},{"custom_field":{"id":"522aec3b52305004c9000001","name":"Liczba","type":"number"},"value":13.0},{"custom_field":{"id":"513dbfdc523050312200008f","name":"Birthday","type":"date"},"value":"2014-08-03T00:00:00Z"}],"modified_at":"2014-02-28T14:13:29Z","address_list":[{"address":"","city":"","state":"","zip_code":"","country_code":""}]}}}
Updating a contact:
PUT /api/v3/contacts/531099895230504785000014.json HTTP/1.1
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept: */*
User-Agent: Ruby
Content-Type: application/json; charset=utf-8
X-Onepagecrm-Uid: 513dbfd85230503122000001
X-Onepagecrm-Ts: 1393596809
X-Onepagecrm-Auth: e21da5e4b581bf41c95bb41f146419020d381cba8352eb3e04b6a1d644b5b806
Host: app.onepagecrm.com
Content-Length: 261
{"first_name":"John","last_name":"Brand","company_name":"Builder & Sons Ltd.","tags":["tag2","tag3"],"starred":false,"custom_fields":[{"id":"522aec5952305004af000002","value":"New single line CF content"},{"id":"513dbfdc523050312200008f","value":"2014-03-08"}]}
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Status: 200 OK
X-OnePageCRM-BuildID: 13540:e15c756d80f9
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
X-Frame-Options: SAMEORIGIN
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: X-OnePageCRM-UID
Access-Control-Allow-Headers: X-OnePageCRM-TS
Access-Control-Allow-Headers: X-OnePageCRM-Auth
Access-Control-Allow-Headers: Content-Type
X-UA-Compatible: IE=Edge
X-Request-Id: 8acbcfb96be0adc4f2a864d13be3e304
X-Runtime: 0.120725
X-Powered-By: Phusion Passenger xxx
Date: Fri, 28 Feb 2014 14:13:29 GMT
Server: nginx/xxx + Phusion Passenger xxx
{"status":0,"message":"OK","timestamp":1393596809,"data":{"contact":{"id":"531099895230504785000014","owner_id":"513dbfd85230503122000001","first_name":"John","last_name":"Brand","job_title":"","description":"","urls":[],"phones":[],"emails":[],"status_id":"5224ae9552305011c000000b","starred":false,"lead_source_id":"","company_name":"Builder & Sons Ltd.","company_id":"531097da523050478500000a","tags":["tag2","tag3"],"custom_fields":[{"custom_field":{"id":"522aec5952305004af000002","name":"Single line","type":"single_line_text"},"value":"New single line CF content"},{"custom_field":{"id":"513dbfdc523050312200008f","name":"Birthday","type":"date"},"value":"2014-03-08T00:00:00Z"}],"modified_at":"2014-02-28T14:13:29Z","address_list":[{"address":"","city":"","state":"","zip_code":"","country_code":""}]}}}
slater at April 3rd, 2014 06:03 — #3
Thanks, that should help me out.
subakva at July 18th, 2014 17:50 — #4
Do you have an example of setting a custom_field value for a "select_box" field? I've tried sending the text of the choice and the index of the selection from the "choices" field, but in both cases, the custom fields aren't populated on the new contact.
Here's a sample request:
{
"type": "company",
"status": "lead",
"lead_source_id": "53c6c054aa76204337000004",
"background": "Some background",
"first_name": "Jason",
"last_name": "Wadsworth",
"company_name": "Spaetzle Incorporated",
"emails": [
{
"type": "work",
"value": "jason@example.com"
}
],
"address_list": [
{
"city": "San Francisco",
"state": "CA"
}
],
"tags": [
"Certification",
"Services"
],
"custom_fields": [
{
"id": "53c95021eb89975db4000013",
"value": "Within a month"
}
]
}
And the details of the custom field:
{
"custom_field": {
"id": "53c95021eb89975db4000013",
"name": "Anticipated CF Launch",
"type": "select_box",
"choices": [
"ASAP",
"Within a month",
"1 - 2 months",
"3+ months"
]
}
}
pete_onepagecrm at July 21st, 2014 11:42 — #5
@subakva - thanks for the heads up. This is an issue on our side.
A fix is on the way and should be released this week.
I'll update you here when it has been released.
Your sample request is in the correct format, it should work as expected when we have made this fix.
Sorry for the inconvenience!
cietoralex1 at July 21st, 2014 15:58 — #7
I'm writting at this topic because my problem is related, so I hope is ok.
Until just a few days ago while creating a subscriber we also added custom fields which were successfully saved. And now the same cod doesn't seem to work anymore, and there is no error triggerd.
Sample json that worked:
{"address_list":[{"city":"Arkansas","zip_code":"000225"}],"first_name":"xulescu","last_name":"xulescu","company_name":"Monsters.inc","emails":[{"type":"other","value":"cietoralex2@gmail.com"}],"status_id":"537c7a2feb8997073b000003","tags":["Contact"],"urls":[{"type":"website","value":"http:\/\/google.com"}],"status":"prospect","lead_source_id":"tradeshow","custom_fields":[{"id":"537ccfb1eb89975459000008","value":"test extra data"},{"id":"537c7a30eb8997073b000034","value":"2014-08-03"}]}
The response is a success but with custom_fields as an emput arrray..so it was ignored.
The custom ids are extracted by calling them from 'custom_fields.json'
Thank you
pete_onepagecrm at July 22nd, 2014 05:22 — #8
This post is no longer valid. Please see my next post below.
Hi folks, @subakva, @cietoralex1
looking into this further, the issue is actually in our documentation.
The format indicated for the custom fields is slightly wrong.
You will need to change your contacts create / update request slightly.
Here is the correct format you will need:
{
'first_name' : 'Johnny',
'last_name' : 'Deer',
'custom_fields' : [
{
'custom_field' : {
'id' : cf_id
},
'value' : 'B'
},
{
'custom_field' : {
'id' : second_cf_id
},
'value' : 'Y'
}
]
}
The custom_fields parameter is an array of objects.
Each object has two parameters, custom_field
which is an object containing the id, and value, containing the value of that custom field.
This format matches the output of custom fields from a GET
request to contacts.json
, which looks like this:
"custom_fields": [
{
"custom_field": {
"id": "53ce2d171da4172a13000044",
"name": "ABCD",
"type": "select_box",
"choices": [
"A",
"B",
"C",
"D"
]
},
"value": "B"
},
{
"custom_field": {
"id": "53ce2d171da4172a13000045",
"name": "XYZ",
"type": "select_box",
"choices": [
"X",
"Y",
"Z"
]
},
"value": "Y"
}
]
pete_onepagecrm at July 22nd, 2014 11:44 — #9
Please feel free to ignore my above post.
We have updated the API to accept both formats.
'custom_fields' : [
'id' : cf_id,
'value' : 'B'
}
or
'custom_fields' : [
{
'custom_field' : {
'id' : cf_id
},
'value' : 'B'
}
lucasas at November 6th, 2014 05:27 — #10
Hi @Pete_OnePageCRM is it possible updating a user's custom field passing just its name. For example:
'custom_fields': [
'name': 'Xpto',
'value': 'B'
]
Since I'm creating or updating a given user from my internal application, I don't know custom_fields ids, so I don't like to compare each custom field.
pete_onepagecrm at November 6th, 2014 07:16 — #11
I'm afraid not @lucasas - you need the custom field id to update it.
fwrmedia at September 4th, 2017 06:17 — #12
Resurrecting an old post here.
My system is posting new contacts via the API which is working fine.
However, introducing custom fields in any of the above mentioned formats fails with the following error.
API call error: Invalid request data
Array
(
)
I was expecting the following to be valid key => values
custom_fields[0][custom_field][id] = [THE_ID]
custom_fields[0][value] = [THE_VALUE]
Thanks
Rob
liam at September 5th, 2017 06:17 — #13
Hello Robert,
Are you sending post data as JSON, or encoding them as query params? I would always advise JSON as it is standardized, while query params can vary greatly for arrays and objects.
Your contact json should look like this:
{
firstname: 'liam',
lastname: 'krewer',
custom_fields: [
{
custom_field: {
id: '1234567890abcdef'
},
value: 'helloworld'
}
]
}
If you must use query params, then it would be the following string:
POST api/v3/contacts.json?firstname=liam&lastname=krewer&custom_fields[][custom_field][id]=1234567890abcdef&custom_fields[][value]=helloworld
Please try on e of the above formats. If they don't work, please let me know what language you are using, and include a copy of the full data you are sending to our API.
Kind regards,
Liam
fwrmedia at September 5th, 2017 07:04 — #14
Hi Liam, thanks for the reply.
It's a PHP system using cURL.
The following creates a contact perfectly: -
POST api/v3/contacts.json?first_name=Fred&last_name=Jackson&company_name=FJackson Ltd&phones[0][type]=work&phones[0][value]=65757565665756&emails[0][type]=work&emails[0][value]=fred@jacksontest.com&background=Some background information&tags[0]=Front page
Result:
Array
(
[status] => 0
[message] => Created
[timestamp] => 1504609527
[data] => stdClass Object
etc
The following is the exact same query but with the addition of a custom field: -
POST api/v3/contacts.json?first_name=Fred&last_name=Jackson&company_name=FJackson Ltd&phones[0][type]=work&phones[0][value]=65757565665756&emails[0][type]=work&emails[0][value]=fred@jacksontest.com&background=Some background information&tags[0]=Front page&custom_fields[0][custom_field][id]=cf_59a81a91eb89970cd6ce42b8&custom_fields[0][value]=my value
Result:
API call error: Invalid request data
Array
(
)
and yes, the arrays are JSON encoded.
fwrmedia at September 5th, 2017 07:23 — #15
JSON view
{
"first_name":"Fred",
"last_name":"Jackson",
"company_name":"FJackson Ltd",
"phones":[
{
"type":"work",
"value":"65757565665756"
}
],
"emails":[
{
"type":"work",
"value":"fred@jacksontest.com"
}
],
"background":"Some background information",
"tags":[
"Front page"
],
"custom_fields":[
{
"custom_field":{
"id":"cf_59a81a91eb89970cd6ce42b8"
},
"value":"my value"
}
]
}
liam at September 5th, 2017 09:52 — #16
Hi Robert,
The JSON data looks correct. But the Custom field id shouldn't be prefixed with cf_
.
Use "id": "59a81a91eb89970cd6ce42b8"
instead.
I'm going to investigate why the error message is empty - normally we provide a validation message.
fwrmedia at September 5th, 2017 10:13 — #17
Thanks Liam, that was it.
I was copying the id from source ( which provides the cf_ ).
Yes, it would have been good to get a descriptive error.
liam at September 5th, 2017 10:26 — #18
Hi Robert,
I reproduced your API post, and I get the following error response:
{
"status":400,
"message":"Invalid request data",
"error_name":"invalid_request_data",
"error_message":"A validation error has occurred",
"errors": {
"custom_fields":"Custom field ID has invalid format"
}
}
fwrmedia at September 5th, 2017 10:52 — #19
Yes, all good here Liam. I was only using the messages and not the errors array when reporting failure.
Thanks for your help it was appreciated.
Powered by Discourse, best viewed with JavaScript enabled