Craig Brass Systems Forum: general usage questions - Craig Brass Systems Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

general usage questions

#1
User is offline   hbidad 

  • Member
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 14-March 09
I'm playing around with the example for getSubmittedTickets in the sticky. I got that working, but lets say I want to change to getSubmittedTicketsWithExtraRestrictions and list tickets that are open, I'm having a bit of problems.

$result = call_user_func_array(array('CBS_KayakoAPI','getSubmittedTicketsWithExtraRestrictions'), $params);

I get the "Unknown Error", but if I echo $result, I get -6. Not sure why the case is not working for me, it didn't with getSubmittedTickets. That aside, by looking at the parameters, everything in getSubmittedTicketsWithExtraRestrictions is available in the example so I'm confused.

PS, I'm new smile.gif
0

#2
User is offline   Andrew Gillard 

  • Staff - Lead Developer
  • Pip
  • Group: Developers
  • Posts: 97
  • Joined: 04-March 07
  • Gender:Male
  • Location:Basingstoke, United Kingdom
If the result of any function call is a negative integer, a specific error has occurred, which that switch() statement uses to give you a textual description of the error.

That said, I've just spotted an error in our example code!

Our example is:
CODE
$result = call_user_func_array(array('CBS_KayakoAPI','getSubmittedTickets'), $params);
if ($result < 0) {
    //The API threw an error
    switch ($result->detail) {
        case -1: "The API username and password that you used are not valid"; break;
        case -2: "An invalid email address was supplied"; break;
... (etc.)


But it should actually be this:
CODE
$result = call_user_func_array(array('CBS_KayakoAPI','getSubmittedTickets'), $params);
if ($result < 0) {
    //The API threw an error
    switch ($result) {
        case -1: "The API username and password that you used are not valid"; break;
        case -2: "An invalid email address was supplied"; break;
... (etc.)

(Notice the removal of "->detail" on the switch() line.)

You should've been seeing some PHP errors from that, though - treating $result as an object when it isn't one...

Hopefully this will solve your problem smile.gif
Andrew Gillard
Lead Developer - Craig Brass Systems
0

#3
User is offline   hbidad 

  • Member
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 14-March 09
Thanks for that, but I'm still confused..

I added an echo to the cases to display the error and added $result to the generic message

example:
CODE
case -6: echo "An invalid sort-by field was specified (must be one of: lastactivity, lastreplier, ticketstatusid, priorityid, departmentid)"; break;

and
CODE
<h1>Kayako API Error</h1><p>'.htmlspecialchars($msg).' '.$result.'</p>


result is -6 "An invalid sort-by field was specified", but I have;

CODE
'sortBy' => 'lastactivity',


The same parameters work with getSubmittedTickets so I believe the this should work with getSubmittedTicketsWithExtraRestrictions according to the documents.

The array looks to be fine;

print_r($params)
CODE
Array ( [user] => user [password] => pass [email] => mytest@email.com [numPerPage] => 100 [specificStatus] => 1 [page] => 1 [sortBy] => lastactivity [orderAsc] => )


I also noticed that value is defined in the api.class and it appears I should be able to remove the variable from the php page to use the default, but still gives the same error

thanks for your help with this
0

#4
User is offline   Andrew Gillard 

  • Staff - Lead Developer
  • Pip
  • Group: Developers
  • Posts: 97
  • Joined: 04-March 07
  • Gender:Male
  • Location:Basingstoke, United Kingdom
Ah, I see the problem, I think. The array keys are confusing. Each array element is passed to the function in the order that they are specified in the array - as call_user_func_array() would work with any other function - rather than to a specific named argument. So you can't rearrange the arguments or leave out middle ones. I should re-write the example code to better explain that, I suppose.

Your array was calling a function like this, which doesn't match the function definition:
CODE
CBS_KayakoAPI::getSubmittedTicketsWithExtraRestrictions("user", "pass", "mytest@email.com", 100, 1, 1, "lastactivity", false);


You'd be better off using something like: (/*..*/ comments added to make it clear what each argument is doing)
CODE
$result = CBS_KayakoAPI::getSubmittedTicketsWithExtraRestrictions($username, $password, $email, /*numPerPage*/ 100, /*page*/ 1, /*sortBy*/ 'lastactivity', /*orderAsc*/ false, /*minStartDate*/ -2147483648, /*maxStartDate*/ 2147483647, /*minLastActivity*/ -2147483648, /*maxLastActivity*/ 2147483647, /*minDueDate*/ -2147483648, /*maxDueDate*/ 2147483647, /*specificDepartment*/ 0, /*specificStatus*/ 1, /*specificPriority*/ 0);

Andrew Gillard
Lead Developer - Craig Brass Systems
0

#5
User is offline   hbidad 

  • Member
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 14-March 09
Excellent!

Thanks for clearing that up for me. Works great!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users