CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Create address using external API: State/Provence issues
Pages: [1]

Author Topic: Create address using external API: State/Provence issues  (Read 1333 times)

robbrandt

  • I post occasionally
  • **
  • Posts: 89
  • Karma: 0
  • CiviCRM version: 4.0.7
  • CMS version: Drupal
  • MySQL version: 5.1.41-3ubuntu12.9
  • PHP version: 5.3.6
Create address using external API: State/Provence issues
December 07, 2012, 04:50:56 pm
Can someone provide me with a functional methodology for creating an address from a new contact via the external API (i.e. from another web application)?

The issue is that the API for creating an address uses state_province_id; a number such as 1004 not a string value like CA or California. I have tried fruitlessly to get it to take a string value, while using the ID works every time in controlled testing. But how could an external web app unrelated to CiviCRM know which ID to use in real life?  Surely building a duplicate database of states & countries isn't reasonable.

I've thought of using the API to get state info by searching on an entered string (search for CA to find out it's 1004, then use 1004 to insert into the new address) but the API apparently doesn't support the state_province table.

FWIW, I would say that about 90% of our Contacts are in the US, but the rest are all over the world.  We need a complete database of states/countries.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Create address using external API: State/Provence issues
December 08, 2012, 12:52:58 am
Hi,

I haven't tried for state, but for countries, you can use the iso code as well as the number

I would suggest to modify the address api so if state is a string, it does a lookup to find the id. It shouldn't be complicated and if you create an issue with patch and test we would more than welcome it.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

robbrandt

  • I post occasionally
  • **
  • Posts: 89
  • Karma: 0
  • CiviCRM version: 4.0.7
  • CMS version: Drupal
  • MySQL version: 5.1.41-3ubuntu12.9
  • PHP version: 5.3.6
Re: Create address using external API: State/Provence issues
December 08, 2012, 08:06:46 am
I've focused mostly on the States, but I did try US and us but I don't think it worked either.

We could create a patch but I'm stunned that there isn't already a solution.  I don't see addresses without statesas useful, therefore no one must be using the external API for addresses.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Create address using external API: State/Provence issues
December 09, 2012, 01:04:39 am
Quote from: robbrandt on December 08, 2012, 08:06:46 am
I don't see addresses without statesas useful, therefore no one must be using the external API for addresses.

FYI, almost every country in Europe doesn't use the state as part of the address. They are some kind of state/region/department/land/county but it is way more often than not ignored.

The address API is used, but indeed would be more useful for the US users to have the state working as a string (name or code). Let us know if you make progress or need help on adding it.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

fen

  • I post frequently
  • ***
  • Posts: 216
  • Karma: 13
    • CivicActions
  • CiviCRM version: 3.3-4.3
  • CMS version: Drupal 6/7
  • MySQL version: 5.1/5.5
  • PHP version: 5.3/5.4
Re: Create address using external API: State/Provence issues
June 05, 2013, 06:46:40 am
I just saw this, and have been able to use a full date name (e.g. 'Pennsylvania') when importing addresses using API vs and the key 'state_province' at least since v4.2 and I think since v3.4...

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Create address using external API: State/Provence issues
June 05, 2013, 03:43:56 pm
Yes, state_province is the documented field - so see create specific field you need to add the action ie

civicrm_api('address', 'getfields', array('version' => 3, 'action' => 'create'));
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Create address using external API: State/Provence issues

This forum was archived on 2017-11-26.