AnsweredAssumed Answered

Missing API file error on AJAX call

Question asked by Richard Coleman on Jan 5, 2016
Latest reply on Jan 5, 2016 by Richard Coleman



I've been struggling with the v10 AJAX framework in Sugar 7.6 and I've got it nearly there I think.


Having tackled authentication, and a number of other problems, I'm stuck with it stating my GET request has a "Missing API File" with a 400 error.


Looking in the console, the URL looks right to me by going to: http://%MY LOCAL SITE%/rest/v10/Accounts/VatCheck?vatReg=123&countryCode=GB


The full object returned by the error in the AJAX is:


readyState: 4,

responseText: "{"error":"unknown_exception","error_message":"Missing API file."}", status: 400, statusText: "Bad Request"}


My code is as follows:



    // Extends from RecordView
    extendsFrom: 'AccountsRecordView',

    initialize: function(options) {
        this._super('initialize', [options]);
  console.log('Custom Record JS in use.');

  saveClicked: function(callback) {
  console.log('save was clicked');

  var vatRegNumber = document.getElementsByName('vat_reg_number_c')[0].value;        
  var countryCodeValue = document.getElementsByName('country_code_c')[0].value;

  console.log("Preparing the Ajax Call");

  beforeSend: function (request)
  request.setRequestHeader("OAuth-Token", SUGAR.App.api.getOAuthToken());
  url: "rest/v10/Accounts/VatCheck",
  type: "GET",
  contentType: "application/json",
  data: { "vatReg" : vatRegNumber , "countryCode" : countryCodeValue },
  dataType: "json",
  success: function(data)
  console.log("AJAX Call successful");
  if (data.success == 1)
  console.log("Result succeeded");
  {'test', {
  level: 'error',
  title: 'Error:',
  messages: data.error,
  error: function (xhr, ajaxOptions, thrownError) {




require_once 'include/api/SugarApi.php';

class VatCheck extends SugarApi

    public function registerApiRest() 
        return array(
            'VatCheck' => array(
                'reqType' => 'GET',
                'path' => array('Accounts', 'VatCheck'),
                'pathVars' => array('vatReg', 'countryCode'),
                'method' => 'checkVatCode',
                'shortHelp' => 'Returns whether the VAT code entered is valid',
                'longHelp' => '',

  public function checkVatCode($api,$args)
  global $db;

  $sql = "call AA_CHECK_VAT_NUMBER_S ('?','?')";

  $params = array($_REQUEST["vatReg"], $_REQUEST["countryCode"]);
  $result = $db->pQuery($sql, $params);

  $row = $db->fetchByAssoc($result);

  if ($row)
  $json = array( 'success' => $row['LS_Success'], 'code' => $row['PS_VAT_Number'], 'error' => $row['errorMessage']);

  return json_encode($json);
  return $db->lastDbError();


I hope someone can point out where I've likely just done something silly here. I've had to make some changes for where it was working in 6.5 using a custom entry point.