Creating a simple REST api

Can someone please help me here. I would like to create a simple REST api, that:
Receives in x2 parameters from a 3rd party application
Once I receive these parameters I need to update and perform various tasks
Upon conclusion, I would like to let the initiating 3rd party application know the result (even the word “done”)
If there is an error, I would like to let the initiating 3rd party application know the error.

I have searched all over the net for answers, and each time I try what seems to work outside of SC, it bombs when trying in SC.

Keep in mind that SC is a php generator, so all that is done in php can be done in SC. In case of a rest-api you don’t have a form interaction. So you need to create blank applications. In rest api parameters are sent by the url as $_GET. Within scriptcase you can use the macro’s to access your database. Nothing more to it.

This is what I am doing. I am getting an error as in the end of this post.
[LEFT][SIZE=13px]I am sorry to disturb with a PM. But I need help . I am trying to develop a rest api in scriptcase. [/SIZE][/LEFT]
[LEFT][SIZE=13px]One I developed using a guidance on the forum it is working fine. But now I want to send parameter. And the same has to be bound. I am getting error that binding parameter is not done. My scriptcase code as follows[/SIZE][/LEFT]

[LEFT][SIZE=13px]header(“Access-Control-Allow-Origin: *”);[/SIZE][/LEFT]
[LEFT][SIZE=13px]header(“Access-Control-Allow-Headers: access”);[/SIZE][/LEFT]
[LEFT][SIZE=13px]header(“Access-Control-Allow-Methods: GET”);[/SIZE][/LEFT]
[LEFT][SIZE=13px]header(“Access-Control-Allow-Credentials: true”);[/SIZE][/LEFT]
[LEFT][SIZE=13px]header(‘Content-Type: application/json’);[/SIZE][/LEFT]

[LEFT][SIZE=13px]// SQL statement parameters[/SIZE][/LEFT]
[LEFT][SIZE=13px]$check_table = ‘products’; // Table name[/SIZE][/LEFT]
[LEFT][SIZE=13px]$check_where = “id = ?”; // Where clause[/SIZE][/LEFT]

[LEFT][SIZE=13px]// Check for record[/SIZE][/LEFT]
[LEFT][SIZE=13px]$check_sql = ‘SELECT *’[/SIZE][/LEFT]
[LEFT][SIZE=13px] . ’ FROM ’ . $check_table[/SIZE][/LEFT]
[LEFT][SIZE=13px] . ’ WHERE ’ . $check_where;[/SIZE][/LEFT]

[LEFT][SIZE=13px]//$check_sql = ‘SELECT * from products where id = 60’;[/SIZE][/LEFT]

[LEFT][SIZE=13px]//$check_sql->bindParam(1, $this->id);[/SIZE][/LEFT]
[LEFT][SIZE=13px]sc_select(rs, $check_sql);[/SIZE][/LEFT]

[LEFT][SIZE=13px]if (false == {rs})[/SIZE][/LEFT]
[LEFT][SIZE=13px]{[/SIZE][/LEFT]
[LEFT][SIZE=13px] // Error while accessing database[/SIZE][/LEFT]
[LEFT][SIZE=13px] http_response_code(404);[/SIZE][/LEFT]
[LEFT][SIZE=13px] echo json_encode(array(‘message’ => ‘Error while accessing database.’));[/SIZE][/LEFT]
[LEFT][SIZE=13px] [/SIZE][/LEFT]
[LEFT][SIZE=13px]}[/SIZE][/LEFT]
[LEFT][SIZE=13px]elseif ({rs}->EOF)[/SIZE][/LEFT]
[LEFT][SIZE=13px]{[/SIZE][/LEFT]
[LEFT][SIZE=13px] // No record found[/SIZE][/LEFT]
[LEFT][SIZE=13px] http_response_code(404);[/SIZE][/LEFT]
[LEFT][SIZE=13px] echo json_encode(array(‘message’ => ‘No Record Found.’));[/SIZE][/LEFT]
[LEFT][SIZE=13px]}[/SIZE][/LEFT]
[LEFT][SIZE=13px]else[/SIZE][/LEFT]
[LEFT][SIZE=13px]{[/SIZE][/LEFT]
[LEFT][SIZE=13px] $rs->MoveFirst();[/SIZE][/LEFT]
[LEFT][SIZE=13px] $id = $rs->fields[0];[/SIZE][/LEFT]
[LEFT][SIZE=13px] $name=$rs->fields[1];[/SIZE][/LEFT]
[LEFT][SIZE=13px] $description=$rs->fields[2];[/SIZE][/LEFT]
[LEFT][SIZE=13px] $price=$rs->fields[3];[/SIZE][/LEFT]
[LEFT][SIZE=13px] $category_id=$rs->fields[4];[/SIZE][/LEFT]
[LEFT][SIZE=13px] $category_name = $rs->fields[5];[/SIZE][/LEFT]

[LEFT][SIZE=13px] $post_item = array([/SIZE][/LEFT]
[LEFT][SIZE=13px] “id” => $id,[/SIZE][/LEFT]
[LEFT][SIZE=13px] “name” => $name,[/SIZE][/LEFT]
[LEFT][SIZE=13px] “description” => html_entity_decode($description),[/SIZE][/LEFT]
[LEFT][SIZE=13px] “price” => $price,[/SIZE][/LEFT]
[LEFT][SIZE=13px] “category_id” => $category_id,[/SIZE][/LEFT]
[LEFT][SIZE=13px] “category_name” => $category_name[/SIZE][/LEFT]

[LEFT][SIZE=13px] );[/SIZE][/LEFT]
[LEFT][SIZE=13px] http_response_code(200);[/SIZE][/LEFT]
[LEFT][SIZE=13px] echo json_encode($post_item);[/SIZE][/LEFT]
[LEFT][SIZE=13px]}[/SIZE][/LEFT]

[LEFT][SIZE=13px]Error returned [/SIZE][/LEFT][LEFT]<TD class=“scErrorMessage” align=“center”>PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: no parameters were bound</TD>[/LEFT]

OK got it working. Thanks to all

Can you tell us how did you solve it? I am in the same case

Thanks

Hi all,
Is there a tutorial or video available that can help to get started with this. I am also interested in best practices on how to access REST API’s and use it’s data to keep an internal database uptodate.

Regards,

No, but using API’s is not out-of-the-box. Scriptcase does have something but I never looked into it as it’s related to certain api’s only. But it really is not that hard. With Curl you access the external api, and with the macro’s of scriptcase you process the response. Depending on the API you get a json encoded string that needs to be decoded. If you consume webservices like this then you can apply this in any module. If you are writing an api that will be called then this needs to be a blank application obviously. Hope this helps.