Answers.Body: <p>It looks like you've found a quirk with the explorer where it's smart enough to convert your string to a number, but when run outside the explorer it's expecting a number for case_type_id.</p>
  
  <p>Use case_type_id = 1, which corresponds to housing_support, which you can see by doing a ('CaseType', 'get') call.</p>
  
  <p>Note that if your script is standalone, i.e. not running within an extension or something where you are already logged in, your <a href="https://docs.civicrm.org/dev/en/latest/framework/bootstrap/" rel="nofollow noreferrer">bootstrapping</a> needs to include something that logs you in, e.g. <code>cv api --user=CMSUser</code>, where CMSUser is the login name for some user with permission to create cases in your CMS.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-22T00:05:18.593Z
Answers.Text: Change to case_type_id = 1, get error "
  Fatal error: Uncaught CiviCRM_API3_Exception: [unknown error: DB Error: unknown error thrown in ..."
Answers.UserDisplayName: adi kusdianto
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-22T00:11:13.257Z
Answers.Text: How are you "logged in" when running the command? You need to provide a CMS user to use for the creator side of the relationship that gets created.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-22T00:14:30.733Z
Answers.Text: I am using php script to create the case. I can create contact, email and address without any problem. Just this case api have strange bugs. The script I have copied from the api explorer.
Answers.UserDisplayName: adi kusdianto
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-22T00:16:56.397Z
Answers.Text: Case kind of requires a little more. Is it a standalone script where you are bootstrapping with cv (e.g. https://docs.civicrm.org/dev/en/latest/framework/bootstrap/)? Then in the cv call you would need to add --user=admin, i.e. a CMS user with appropriate permissions.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-22T01:11:34.690Z
Answers.Text: I will try using the cv, need time to learn it 1st, the cv. Thank you for the guide
Answers.UserDisplayName: adi kusdianto
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-22T01:15:22.340Z
Answers.Text: I notice you're on joomla. The same link above gives a little bit about bootstraping with joomla, but I don't know joomla very well so don't know how to "log in" during the bootstrap process.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-22T02:14:59.017Z
Answers.Text: Yes, i am using joomla.
  Using the cv, the error still same, here is the error
  http://prntscr.com/n1944f, same error using the joomla.
  
   _civicrm_api3_case_create_xmlProcessor
  
  on that function, the bugs happen
Answers.UserDisplayName: adi kusdianto
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-22T02:22:14.557Z
Answers.Text: Yes it's a relationship error. You have to add --user=something to the cv command. For example if you have a joomla user named Adi who has permission to create cases, you need to say `cv api --user=Adi Case.create ...`
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-22T02:26:50.307Z
Answers.Text: fantastic... 
  
  it is working 
  
  http://prntscr.com/n196t6
Answers.UserDisplayName: adi kusdianto
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-22T02:31:01.270Z
Answers.Text: Great! Can you mark as answered? (click the gray checkmark just to the left of the answer)
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-22T02:32:31.143Z
Answers.Text: with the cv is working, using the php script, how to assign --user=something
  
  I prefer using the php script than the cv.
  
  Any idea ?
Answers.UserDisplayName: adi kusdianto
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-22T02:34:27.530Z
Answers.Text: For joomla I don't know. You'd use something like this: https://docs.civicrm.org/dev/en/latest/framework/bootstrap/#joomla, but you'd have to add some line that logs you in. Maybe you can ask a separate question and someone will answer.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-22T02:37:15.397Z
Answers.Text: i will find out..
  thank's Demerit
Answers.UserDisplayName: adi kusdianto
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-21T22:39:57.003Z
Answers.LastActivityDate: 2019-03-22T02:25:58.503Z
Answers.LastEditDate: 2019-03-22T02:25:58.503Z
Answers.UserDisplayName: Demerit
Body: <p>Using CiviCRM API v3 Explorer, i can create case without any problem. I can see the new case on case dash board, but using the  php script, there are an error exception happen</p>
  
  <blockquote>
    <p>Fatal error: Uncaught CiviCRM_API3_Exception: [unknown error: DB
    Constraint Violation - case_type_id should possibly be marked as
    mandatory for Case,create API. If so, please raise a bug report.
    thrown in
     /idev/joom/administrator/components/com_civicrm/civicrm/api/api.php
    on line 45</p>
  </blockquote>
  
  <p>Here is the snippet code</p>
  
  <p><a href="http://prntscr.com/n17bng" rel="nofollow noreferrer">http://prntscr.com/n17bng</a></p>
  
  <p>this is the output</p>
  
  <p><a href="http://prntscr.com/n17c6f" rel="nofollow noreferrer">http://prntscr.com/n17c6f</a></p>
  
  <p>Changing code to </p>
  
  <p><a href="http://prntscr.com/n17cky" rel="nofollow noreferrer">http://prntscr.com/n17cky</a></p>
  
  <p>get this error</p>
  
  <p><a href="http://prntscr.com/n17cqv" rel="nofollow noreferrer">http://prntscr.com/n17cqv</a></p>
  
  <p>Using the explorer code, all is running well</p>
  
  <p><a href="http://prntscr.com/n17d48" rel="nofollow noreferrer">http://prntscr.com/n17d48</a></p>
  
  <p>Anyone know why this happen ?</p>
  
  <p>Thank you</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-21T12:40:34.217Z
Comments.Text: In your script are you setting a value for case_type? Can you edit your question to show what parameters you are passing?
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-21T22:36:08.693Z
Comments.Text: Hi Demerit, i have update  my question, i am passing "house_support", changing using 'case_type_id' => 'housing_support', i have no luck too.. thank you
Comments.UserDisplayName: adi kusdianto
Tags: <civicase>
Title: civi case API unable to create case
ThreadText: # civi case API unable to create case
  
  (Asked by: username_0 on 2019-03-21)
  
  Using CiviCRM API v3 Explorer, i can create case without any problem. I can see the new case on case dash board, but using the php script, there are an error exception happen
  
  > Fatal error: Uncaught CiviCRM\_API3\_Exception: [unknown error: DB
  > Constraint Violation - case\_type\_id should possibly be marked as
  > mandatory for Case,create API. If so, please raise a bug report.
  > thrown in
  > /idev/joom/administrator/components/com\_civicrm/civicrm/api/api.php
  > on line 45
  
  Here is the snippet code
  
  <http://prntscr.com/n17bng>
  
  this is the output
  
  <http://prntscr.com/n17c6f>
  
  Changing code to
  
  <http://prntscr.com/n17cky>
  
  get this error
  
  <http://prntscr.com/n17cqv>
  
  Using the explorer code, all is running well
  
  <http://prntscr.com/n17d48>
  
  Anyone know why this happen ?
  
  Thank you
  
  **Tags:** civicase
  
  > **Comments:**
  > **username_1**: In your script are you setting a value for case_type? Can you edit your question to show what parameters you are passing?  
  > **username_0**: Hi username_1, i have update  my question, i am passing "house_support", changing using 'case_type_id' => 'housing_support', i have no luck too.. thank you  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-03-21. Score: 0 | Accepted answer
  
  It looks like you've found a quirk with the explorer where it's smart enough to convert your string to a number, but when run outside the explorer it's expecting a number for case\_type\_id.
  
  Use case\_type\_id = 1, which corresponds to housing\_support, which you can see by doing a ('CaseType', 'get') call.
  
  Note that if your script is standalone, i.e. not running within an extension or something where you are already logged in, your [bootstrapping](https://docs.civicrm.org/dev/en/latest/framework/bootstrap/) needs to include something that logs you in, e.g. `cv api --user=CMSUser`, where CMSUser is the login name for some user with permission to create cases in your CMS.
  
  > **Comments:**
  > **username_0**: Change to case_type_id = 1, get error " Fatal error: Uncaught CiviCRM_API3_Exception: [unknown error: DB Error: unknown error thrown in ..."  
  > **username_1**: How are you "logged in" when running the command? You need to provide a CMS user to use for the creator side of the relationship that gets created.  
  > **username_0**: I am using php script to create the case. I can create contact, email and address without any problem. Just this case api have strange bugs. The script I have copied from the api explorer.  
  > **username_1**: Case kind of requires a little more. Is it a standalone script where you are bootstrapping with cv (e.g. https://docs.civicrm.org/dev/en/latest/framework/bootstrap/)? Then in the cv call you would need to add --user=admin, i.e. a CMS user with appropriate permissions.  
  > **username_0**: I will try using the cv, need time to learn it 1st, the cv. Thank you for the guide  
  > **username_1**: I notice you're on joomla. The same link above gives a little bit about bootstraping with joomla, but I don't know joomla very well so don't know how to "log in" during the bootstrap process.  
  > **username_0**: Yes, i am using joomla. Using the cv, the error still same, here is the error http://prntscr.com/n1944f, same error using the joomla.   _civicrm_api3_case_create_xmlProcessor  on that function, the bugs happen  
  > **username_1**: Yes it's a relationship error. You have to add --user=something to the cv command. For example if you have a joomla user named Adi who has permission to create cases, you need to say `cv api --user=Adi Case.create ...`  
  > **username_0**: fantastic...   it is working   http://prntscr.com/n196t6  
  > **username_1**: Great! Can you mark as answered? (click the gray checkmark just to the left of the answer)  
  > **username_0**: with the cv is working, using the php script, how to assign --user=something  I prefer using the php script than the cv.  Any idea ?  
  > **username_1**: For joomla I don't know. You'd use something like this: https://docs.civicrm.org/dev/en/latest/framework/bootstrap/#joomla, but you'd have to add some line that logs you in. Maybe you can ask a separate question and someone will answer.  
  > **username_0**: i will find out.. thank's username_1  
  
  ---
  
  