Jump to content
  • 0

Non Descriptive Errors In Api Calls


jbatalha

Question

Hello,

 

We're experimenting with Blesta. We are trying to migrate our client list to the Blesta installation. We've managed to connect and find the right model to call, but we keep getting the Error that required fields are not being included in the array being sent over to Blesta.

 

Problem is, the API just says that a required field is missing, not WHICH required field is missing. This complicates matters greatly and makes developing integrations very very slow.

 

Is there a workaround, patch or something that we can use to have Blesta tell us which fields triggered the required error? And if there isn't, could you point me to the location in the code where I could maybe make it happen?

 

Thank you in advance,

João Batalha

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Are you using the API SDK to handle this, or are you calling models directly?

 

Validation errors are set when input fails validation, and you can access them by calling the errors() method, e.g.

<?php
...

// Set input vars
$vars = array();

// Attempt to create the client
$client_id = $this->Clients->add($vars);

// Show any validation errors
if (($errors = $this->Clients->errors()) {
    print_r($errors);
    die;
}

...
?>

 

You may want to also take a look at the source docs if you haven't already.

Link to comment
Share on other sites

  • 0

Hi guys,

 

Thank you for the quick responses.

 

@Tyson: I am using the API SDK and integrating it with Drupal 7.

 

 

This is a snippet of my code:

      $api = new BlestaApi($url, $user, $key);     

      $params = array(
        ...
      );
      
      $response = $api->post("clients", "create", $params);
      //dsm($response->response());
      dsm($response->errors());

 

This is the output of $response->errors() in Krumo Debug:

(Object) stdClass
  error (Object) stdClass
    message 
      (String, 28 characters ) An unexpected error occured.
    response 
      (String, 25 characters ) Parameter is not optional

 

As you can see, neither the error nor the response hints at what field is missing. In big models with dozens of fields this is a huge hurdle.

Link to comment
Share on other sites

  • 0

That error tells you that one of the required parameters (required by the resource you're requesting) is not being provided. Check the source docs to see which parameters are required and ensure you're passing them in (http://source-docs.blesta.com/class-Clients.html#_create).

 

Since that method only requires a single parameter it looks like you're missing the "vars" parameter. You should have something like:

 

$params = array(
    'vars' => array(
        // all indexes required by the $vars parameter as per the source docs.
    )
);
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...