1

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

  • In your script are you setting a value for case_type? Can you edit your question to show what parameters you are passing? – Demerit Mar 21 at 12:40
  • 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 – adi kusdianto Mar 21 at 22:36
0

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 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.

  • Change to case_type_id = 1, get error " Fatal error: Uncaught CiviCRM_API3_Exception: [unknown error: DB Error: unknown error thrown in ..." – adi kusdianto Mar 22 at 0:05
  • 1
    Case kind of requires a little more. Is it a standalone script where you are bootstrapping with cv (e.g. 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. – Demerit Mar 22 at 0:16
  • 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 ... – Demerit Mar 22 at 2:22
  • 1
    fantastic... it is working prntscr.com/n196t6 – adi kusdianto Mar 22 at 2:26
  • 1
    For joomla I don't know. You'd use something like this: 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. – Demerit Mar 22 at 2:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.