Can I create an API with SC9?

Hi guys,
I could have sworn that I read or heard something about SC 9 having the capability to expose an API or service to the web.
Does anyone know?
​Thanks

That’s even possible with version 6. Use a blank application to expose your functions. If you are using webservices you need to expose a WSDL. To be able to do that you need to use NuSoap or the standard soap php routines

Thanks. I was thinking that SC’s grid apps must have something they internally call for various Ajax updating, like when they have the grid that scrolls down forever. Wouldn’t it be making an asynchronous database read to populate the rows? If we could figure out how they are doing that, it might be handy.

I guess something along the lines of https://github.com/mevdschee/php-crud-api would work in a blank app.

I would appreciate if some one posts an example for this. I tried to create a blank application and wrote the API. But when I call it, it is getting downloaded. In some Youtube video for creating php someone explained that i need to use header(“Content-Type:applicaiton/json”); as the first statement. So, for me it is not working as I don’t know

I finally figured out and posting here for others benefit

  1. I have created a blank application
  2. created a php function and called this function from OnExecute event

The following is the content of the php function under Programming PHP methods

header(‘Access-Control-Allow-Origin: *’);
header(‘Content-Type: application/json’);

$data_arr = array();
$data_arr[‘data’] = array();

$check_sql = ‘SELECT categoryid, categoryname’
. ’ FROM categories’;

sc_select(rs, $check_sql);

if (false == {rs})
{
echo json_encode(array(‘message’ => ‘Error while accessing database.’));
}
else
{
while(!$rs->EOF)
{
$id = $rs->fields[0];
$categoryname = $rs->fields[1];

    $post_item = array(
        'id' => $id,
        'category' => $categoryname            
        );

   array_push ($data_arr['data'], $post_item);

    $rs->MoveNext();
}
$rs->Close();
echo json_encode($data_arr);

}

1 Like