Title: Use API Parameters in Custom SQL Query Endpoint
Last modified: December 9, 2022

---

# Use API Parameters in Custom SQL Query Endpoint

 *  Resolved [esamzenhom](https://wordpress.org/support/users/esamzenhom/)
 * (@esamzenhom)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/use-api-parameters-in-custom-sql-query-endpoint/)
 * Hi,
 * Could i know if we can use Custom Parameters in Custom SQL Query Endpoint?

Viewing 10 replies - 1 through 10 (of 10 total)

 *  Thread Starter [esamzenhom](https://wordpress.org/support/users/esamzenhom/)
 * (@esamzenhom)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/use-api-parameters-in-custom-sql-query-endpoint/#post-16279103)
 * Cause I received no reply, I Managed to add Parameters by the following snippet,
   Hope it will benefit somebody searching :
 * add_filter( ‘rest_routes_custom_sql_query’, ‘ss’ ,99,3);
    function ss($query,
   $data,$endpoint) { $url = (isset($_SERVER[‘HTTPS’]) && $_SERVER[‘HTTPS’] === ‘
   on’ ? “https” : “http”) . “://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]”; $url_components
   = parse_url($url); parse_str($url_components[‘query’], $params); $query = str_replace(“
   <Parameter1>”, $params[‘Parameter1’], $query); $query = str_replace(“<Parameter2
   >”, $params[‘Parameter2’], $query);
 *  return $query;
    }`
 *  [financialcoder](https://wordpress.org/support/users/financialcoder/)
 * (@financialcoder)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/use-api-parameters-in-custom-sql-query-endpoint/#post-16326828)
 * I am writing a simple Custom MySQL Query, as follows:
   UPDATE zaqgutmy_WPUKX.NK_MKTSTATUS
   SET code = $signal WHERE instrument = $symbolI want the plugin to replace the
   2 variables started with $, by the actual Custom Parameters…. But it is not being
   accepted… What would be the expected format to write this snipped to replace 
   the Custom Parameter by its value coming from the http request ?
 *  [financialcoder](https://wordpress.org/support/users/financialcoder/)
 * (@financialcoder)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/use-api-parameters-in-custom-sql-query-endpoint/#post-16326837)
 * I have also attempted the Custom SQL Query with the following Sintax :
   UPDATE
   zaqgutmy_WPUKX.NK_MKTSTATUS SET code = <Parameter1> WHERE instrument = “<Parameter2
   >”But the plugin responds with this:
 * {
 *     “success”: **false**,
 *     “data”: “You have an error in your SQL syntax; check the manual that corresponds
   to your MySQL server version for the right syntax to use near ‘<Parameter1> WHERE
   instrument = “<Parameter2>”’ at line 1”
 * }
 *  [financialcoder](https://wordpress.org/support/users/financialcoder/)
 * (@financialcoder)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/use-api-parameters-in-custom-sql-query-endpoint/#post-16328419)
 * So, it is not clear how to tell the plugin to replace the variables in the MySQL
   query, with data received from the API that the plugin is creating… would you
   mind clarifying the syntax required by the plugin, please…. I couldn’t find it
   anywhere in the plugin documentation.
 *  Thread Starter [esamzenhom](https://wordpress.org/support/users/esamzenhom/)
 * (@esamzenhom)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/use-api-parameters-in-custom-sql-query-endpoint/#post-16328464)
 * ![](https://i0.wp.com/i.ibb.co/s3wDGLS/aaa.jpg?ssl=1)
 * please see the previous image
 *  Thread Starter [esamzenhom](https://wordpress.org/support/users/esamzenhom/)
 * (@esamzenhom)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/use-api-parameters-in-custom-sql-query-endpoint/#post-16328475)
 * i think you should replace the dollar sign, because its not allowed in the URL,
   instead, you can use <parameter>, for both api parameter and sql parameter
 *  Thread Starter [esamzenhom](https://wordpress.org/support/users/esamzenhom/)
 * (@esamzenhom)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/use-api-parameters-in-custom-sql-query-endpoint/#post-16328492)
 * **if you wonder where to write the previous code, **
 * This is a code snippet, it should be added to Functions.php file, or better, 
   to be added as a snippet in a plugin called “**Code Snippets**“,
 *  Plugin Author [Rest Routes](https://wordpress.org/support/users/wp-making/)
 * (@wp-making)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/use-api-parameters-in-custom-sql-query-endpoint/#post-16330336)
 * Hello,
 * We are working to support URL parameter placeholders in SQL queries by default,
   it should be available very soon. For now, I suggest using [@esamzenhom](https://wordpress.org/support/users/esamzenhom/)
   approach with custom code.
 *  Plugin Author [Rest Routes](https://wordpress.org/support/users/wp-making/)
 * (@wp-making)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/use-api-parameters-in-custom-sql-query-endpoint/#post-16330964)
 * Good news! We just added this feature and one more really cool: [https://restroutes.com/rest-routes-5-5-0/](https://restroutes.com/rest-routes-5-5-0/)
 * Please let us know what you think about it.
 *  [financialcoder](https://wordpress.org/support/users/financialcoder/)
 * (@financialcoder)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/use-api-parameters-in-custom-sql-query-endpoint/#post-16331061)
 * Thats amazing ! I will try the new features !
   Thanks both of you for the messages!

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Use API Parameters in Custom SQL Query Endpoint’ is closed to new replies.

 * ![](https://ps.w.org/rest-routes/assets/icon-128x128.png?rev=1337282)
 * [Rest Routes – Custom Endpoints for WordPress REST API](https://wordpress.org/plugins/rest-routes/)
 * [Support Threads](https://wordpress.org/support/plugin/rest-routes/)
 * [Active Topics](https://wordpress.org/support/plugin/rest-routes/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/rest-routes/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/rest-routes/reviews/)

 * 10 replies
 * 3 participants
 * Last reply from: [financialcoder](https://wordpress.org/support/users/financialcoder/)
 * Last activity: [3 years, 5 months ago](https://wordpress.org/support/topic/use-api-parameters-in-custom-sql-query-endpoint/#post-16331061)
 * Status: resolved