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) »
  • State_Province Missing From V2/V3 CiviCRM APIs?
Pages: [1]

Author Topic: State_Province Missing From V2/V3 CiviCRM APIs?  (Read 2009 times)

miko

  • I post occasionally
  • **
  • Posts: 75
  • Karma: 2
  • CiviCRM version: 3.4.5
  • CMS version: Drupal 6.22
  • MySQL version: 5.0.77
  • PHP version: 5.2.11
State_Province Missing From V2/V3 CiviCRM APIs?
April 24, 2011, 05:54:33 pm
Eileen and Xavier helped me a lot today.  But after I got the address fields on my screen, I realized that STATE was not showing.  Printing the Address $results array yields this:

Array ( [is_error] => 0 [version] => 3 [count] => 1 [id] => 5 [values] => Array ( [5] => Array ( [id] => 5 [contact_id] => 7 [location_type_id] => 6 [is_primary] => 1 [is_billing] => 0 [street_address] => 1055 MacArthur Boulevard [city] => Oakland [state_province_id] => 1004 [postal_code] => 94610 [country_id] => 1228 ) ) )

So I am now trying to convert "[state_province_id] => 1004" into the state of CA.

Is the StateProvince.PHP missing from the API or does it have another name?  Thanks!

miko

  • I post occasionally
  • **
  • Posts: 75
  • Karma: 2
  • CiviCRM version: 3.4.5
  • CMS version: Drupal 6.22
  • MySQL version: 5.0.77
  • PHP version: 5.2.11
Re: State_Province Missing From V2/V3 CiviCRM APIs?
April 24, 2011, 06:40:10 pm
By some miracle!  By some miracle I figured this out myself.  But I would like to ask that in the V3 API "examples", please show ACTUAL examples, like I'm about to show below.  Because it was impossible to just GUESS what the id field (the require param) was the Constant get statement.  ALSO, there was no documentation in the Address examples that the state codes are accessed through Constant.php.

So here's the necessary code:

$tmp_state = civicrm_api('constant','get', array('version' => '3', 'name' => 'stateProvince'));

Yay!  I feel like i'm my own here here.  But at least now YOU have the answer if you end up having this problem.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: State_Province Missing From V2/V3 CiviCRM APIs?
April 24, 2011, 11:10:08 pm
Can you add this example in the wiki ?

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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: State_Province Missing From V2/V3 CiviCRM APIs?
April 26, 2011, 01:31:19 pm
Hi,

I think we can document this in code & just add a pointer to it on the wiki. We could add something like 'return.options' to constant get, advertise it through getFields & if called it could return a list of the possible psuedoconstants available (ie. the properties of the class being called)
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

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: State_Province Missing From V2/V3 CiviCRM APIs?
April 26, 2011, 02:00:46 pm
Code: [Select]
$results=civicrm_api("Constant","get", array ('version' =>'3', return=>''options"));
Is what you're suggesting to get the list of names ? Don't like it, I'd prefer
$results=civicrm_api("Constant","getnames", array ('version' =>'3')); (but would be harder to guess the name of the action getnames)

or
$results=civicrm_api("Constant","getfields", array ('version' =>'3'));

because getfields is more standard, isn't used for constant already (as the fields return depends on the name anyway).

Not sure I like Constant and an entity in general, that's a kind of unclear box that contains about everything without having a clear boundary.

Shouldn't it be better to expose as separate entities countries, states... ?


Would have been dead easy to implement if entity was a class with methods instead of independent civicrm_api3_xxx functions (was it your or andreas suggestion a while ago) ?
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: State_Province Missing From V2/V3 CiviCRM APIs?
April 26, 2011, 02:13:17 pm
Yeah - we can do with getfields - there is only one possible field but many options so we'll just have to put them into the fields array somehow. I think constant returns a mix of option values & entities.

We could write an api for states, counties etc but I guess making constant available means that constants are available that we haven't felt the need to write yet
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

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: State_Province Missing From V2/V3 CiviCRM APIs?
April 26, 2011, 03:49:22 pm
Done.

api/v3/Constant.php
Committed revision 33919.

What I could have been using: being able to fetch all the info on countries (ie iso code, world region, name, id...). being able to activate/desactivate countries (I hate the localization web interface).

Some of the constants are have already an entity (RElationshipType) and are IMO wrongly part of the constants (eg Tag). We might want to remove them from the doc/list to avoid confusion?
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

miko

  • I post occasionally
  • **
  • Posts: 75
  • Karma: 2
  • CiviCRM version: 3.4.5
  • CMS version: Drupal 6.22
  • MySQL version: 5.0.77
  • PHP version: 5.2.11
Re: State_Province Missing From V2/V3 CiviCRM APIs?
April 27, 2011, 03:05:10 pm
X+,

My example was not to get a list of names, just the one abbreviation for the one site.

I don't know about "getfields" and "getnames" - where can I learn what they mean and how they differ from "get"?  Are you saying that I'm using a form that's going to be obsoleted?

Eileen and Xavi- thanks for considering adding more examples to the documentation.

miko

  • I post occasionally
  • **
  • Posts: 75
  • Karma: 2
  • CiviCRM version: 3.4.5
  • CMS version: Drupal 6.22
  • MySQL version: 5.0.77
  • PHP version: 5.2.11
Re: State_Province Missing From V2/V3 CiviCRM APIs?
April 27, 2011, 03:08:40 pm
Xavier-

I agree that I was very surprised to find states and provinces in "constants"...

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: State_Province Missing From V2/V3 CiviCRM APIs?
April 27, 2011, 04:17:21 pm
getFields is a function that tells you what fields are available for an api - it is called by the api explorer so you can see what the options are (you can also call it directly). get is just what you have been using it for & you can disregard 'getnames'

http://sandbox.civicrm.org/civicrm/ajax/doc#explorer
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) »
  • State_Province Missing From V2/V3 CiviCRM APIs?

This forum was archived on 2017-11-26.