Answers.Body: <p>This was curious, so I tracked it down.</p>
  
  <p>Apparently the list of valid currencies predates the <code>civicrm_currency</code> table.  So right now the valid currencies are hardcoded - you can see that in <code>&lt;civiroot&gt;/CRM/Core/Pseudoconstant.php</code> around line 1077 - the <code>currencyCode()</code> function.</p>
  
  <p>As a quick workaround, you could add your currency to the list.  However, the correct solution would be to modify this function to return the result of <code>SELECT name FROM civicrm_currency</code>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-16T17:08:05.700Z
Answers.LastActivityDate: 2018-01-16T17:08:05.700Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.Body: <p>I tried to replicate it in Civicrm 4.7.23 and Drupal 7.56 and i also got same error message through API call:</p>
  
  <p><code>$result = civicrm_api3('Contribution', 'create', array(
    'financial_type_id' =&gt; "Donation",
    'total_amount' =&gt; 100,
    'contact_id' =&gt; 202,
    'currency' =&gt; "RSD",
  ));</code></p>
  
  <p>Looks like its bug (maybe) in civicrm, i have created Jira issue <a href="https://issues.civicrm.org/jira/browse/CRM-21664" rel="nofollow noreferrer">here</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-16T15:55:30.910Z
Answers.LastActivityDate: 2018-01-16T17:16:02.043Z
Answers.LastEditDate: 2018-01-16T17:16:02.043Z
Answers.UserDisplayName: Hassan Farooq
Body: <p>I noticed importing or adding contributions in Serbian dinars (RSD) doesn't work. I tried using API Explorer to create a contribution that way but I get the same error I get when I try to import contributions.</p>
  
  <pre><code>{"sequential":1,"financial_type_id":"Donation","total_amount":100,"contact_id":2,"currency":"RSD"}
  </code></pre>
  
  <blockquote>
    <p>"error_message": "Currency not a valid code: "</p>
  </blockquote>
  
  <p>I then tried to find out are there other currencies that don't work and I tried importing a file with donations in all currencies in the <code>civicrm_currency</code> table. It turns out that there three more currencies which don't work.</p>
  
  <p>The currencies affected are: </p>
  
  <ul>
  <li><p>Serbian Dinar (RSD)</p></li>
  <li><p>Venezuela Bolivar (VEF)</p></li>
  <li><p>Azerbaijanian Manat (AZN)</p></li>
  <li><p>Mozambique Metical (MZN)</p></li>
  </ul>
  
  <p>When I try to add a contribution manually through the form using these currencies, CiviCRM disregards my selection and uses the default currency.</p>
  
  <p>There is a workaround. You can set any of these affected currencies as default, and then leave the field for currencies blank for that currency when importing (or leave default when adding a contribution manually). CiviCRM will then assume you are using a default currency and import or add it correctly. Still there's a problem if you want to use other currency for default (USD for example) and add contributions in affected currencies.</p>
  
  <p>What could be causing this?</p>
  
  <p>I'm using the current version of CiviCRM (4.7.29)</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-01-16T23:48:46.523Z
Comments.Text: Teamwork makes the dream work!  12 hours after Marko asked this question, I tracked down the cause and Hassan Farooq wrote the fix.  Thanks to you both for improving CiviCRM!  The fix will be in 4.7.31+.
Comments.UserDisplayName: Jon G - Megaphone Tech
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-01-17T08:53:15.827Z
Comments.Text: Great work, people!
Comments.UserDisplayName: Marko
Tags: <civicontribute><api><core><currency><data-import>
Title: Adding contributions doesn't work for certain currencies
ThreadText: # Adding contributions doesn't work for certain currencies
  
  (Asked by: username_0 on 2018-01-16)
  
  I noticed importing or adding contributions in Serbian dinars (RSD) doesn't work. I tried using API Explorer to create a contribution that way but I get the same error I get when I try to import contributions.
  {"sequential":1,"financial_type_id":"Donation","total_amount":100,"contact_id":2,"currency":"RSD"}
  
  
  "error_message": "Currency not a valid code: "
  
  I then tried to find out are there other currencies that don't work and I tried importing a file with donations in all currencies in the civicrm_currency table. It turns out that there three more currencies which don't work.
  The currencies affected are: 
  
  Serbian Dinar (RSD)
  Venezuela Bolivar (VEF)
  Azerbaijanian Manat (AZN)
  Mozambique Metical (MZN)
  
  When I try to add a contribution manually through the form using these currencies, CiviCRM disregards my selection and uses the default currency.
  There is a workaround. You can set any of these affected currencies as default, and then leave the field for currencies blank for that currency when importing (or leave default when adding a contribution manually). CiviCRM will then assume you are using a default currency and import or add it correctly. Still there's a problem if you want to use other currency for default (USD for example) and add contributions in affected currencies.
  What could be causing this?
  I'm using the current version of CiviCRM (4.7.29)
  
  **Tags:** civicontribute, api, core, currency, data-import
  
  > **Comments:**
  > **username_1**: Teamwork makes the dream work!  12 hours after username_0 asked this question, I tracked down the cause and username_2 wrote the fix.  Thanks to you both for improving CiviCRM!  The fix will be in 4.7.31+.  
  > **username_0**: Great work, people!  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-01-16. Score: 2 | Accepted answer
  
  This was curious, so I tracked it down.
  
  Apparently the list of valid currencies predates the `civicrm_currency` table. So right now the valid currencies are hardcoded - you can see that in `/CRM/Core/Pseudoconstant.php` around line 1077 - the `currencyCode()` function.
  
  As a quick workaround, you could add your currency to the list. However, the correct solution would be to modify this function to return the result of `SELECT name FROM civicrm_currency`.
  
  
  ---
  
  ### Answer by username_2 on 2018-01-16. Score: 1
  
  I tried to replicate it in Civicrm 4.7.23 and Drupal 7.56 and i also got same error message through API call:
  
  `$result = civicrm_api3('Contribution', 'create', array(
  'financial_type_id' => "Donation",
  'total_amount' => 100,
  'contact_id' => 202,
  'currency' => "RSD",
  ));`
  
  Looks like its bug (maybe) in civicrm, i have created Jira issue [here](https://issues.civicrm.org/jira/browse/CRM-21664).
  
  
  ---
  
  