# We want to utilize CREATE \[OR REPLACE\] EXTERNAL FUNCTION to call a REST API

**URL:** <https://www.singlestore.com/forum/t/we-want-to-utilize-create-or-replace-external-function-to-call-a-rest-api/4858>\
**Category:** Connectors and Pipelines\
**Created:** [August 9, 2022, 10:01am UTC](https://www.singlestore.com/forum/t/we-want-to-utilize-create-or-replace-external-function-to-call-a-rest-api/4858 "2022-08-09T10:01:26Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![prakash.n.gour](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/p/bb73d2/32.png) [@prakash.n.gour](https://www.singlestore.com/forum/u/prakash.n.gour)\
**Post date:** [August 9, 2022, 10:01am UTC](https://www.singlestore.com/forum/t/we-want-to-utilize-create-or-replace-external-function-to-call-a-rest-api/4858/1 "2022-08-09T10:01:26Z")

</div>

Hi Team,  
We would like to invoke an external service from Singlestore StoredProcedure and exploring External Function feature but in docs it says -  
“CREATE [OR REPLACE] EXTERNAL FUNCTION` is currently a private preview feature and must be enabled via a Support Request for SingleStoreDB Cloud users.”

 ![image](https://forum-prod-assets20231213123829991800000001.s3.dualstack.us-east-1.amazonaws.com/original/2X/f/f603ce040a5c5ef7893dfa6190950bb0042278ae.png)

Can you please suggest if it is possible for us to use this feature and how we can enable it. Currently we are using on - premise database.

When we tried this we got error like “ERROR 2576 UNKNOWN\_ERR\_CODE: External function runtime failure: Couldn’t connect to server”

Thanks.

---

<div class="post-metadata">

**Author:** ![prakash.n.gour](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/p/bb73d2/32.png) [@prakash.n.gour](https://www.singlestore.com/forum/u/prakash.n.gour)\
**Post date:** [August 9, 2022, 3:07pm UTC](https://www.singlestore.com/forum/t/we-want-to-utilize-create-or-replace-external-function-to-call-a-rest-api/4858/2 "2022-08-09T15:07:40Z")

</div>

Hi Team , any response please

---

<div class="post-metadata">

**Author:** ![MariaSilverhardt](https://www.singlestore.com/forum/user_avatar/www.singlestore.com/mariasilverhardt/32/828_2.png) [@MariaSilverhardt](https://www.singlestore.com/forum/u/MariaSilverhardt)\
**Post date:** [August 9, 2022, 8:21pm UTC](https://www.singlestore.com/forum/t/we-want-to-utilize-create-or-replace-external-function-to-call-a-rest-api/4858/3 "2022-08-09T20:21:28Z")

</div>

Hi prakash! Welcome! 👋

Can you please supply the version number you are running on?

Thanks

---

<div class="post-metadata">

**Author:** ![prakash.n.gour](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/p/bb73d2/32.png) [@prakash.n.gour](https://www.singlestore.com/forum/u/prakash.n.gour)\
**Post date:** [August 10, 2022, 9:21am UTC](https://www.singlestore.com/forum/t/we-want-to-utilize-create-or-replace-external-function-to-call-a-rest-api/4858/4 "2022-08-10T09:21:08Z")

</div>

I see below when I executing like below

cmd\>docker exec -it singlestore-ciab memsql -p  
Enter password:  
Welcome to the MySQL monitor. Commands end with ; or \g.  
Your MySQL connection id is 504  
**Server version: 5.7.32 MemSQL** source distribution (compatible; MySQL Enterprise & MySQL Commercial)

Also in other environment we have - DB version is : **7.5.18**

---

<div class="post-metadata">

**Author:** ![prakash.n.gour](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/p/bb73d2/32.png) [@prakash.n.gour](https://www.singlestore.com/forum/u/prakash.n.gour)\
**Post date:** [August 11, 2022, 10:38am UTC](https://www.singlestore.com/forum/t/we-want-to-utilize-create-or-replace-external-function-to-call-a-rest-api/4858/5 "2022-08-11T10:38:41Z")

</div>

Hi Team , please respond

---

<div class="post-metadata">

**Author:** ![prakash.n.gour](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/p/bb73d2/32.png) [@prakash.n.gour](https://www.singlestore.com/forum/u/prakash.n.gour)\
**Post date:** [August 12, 2022, 1:54pm UTC](https://www.singlestore.com/forum/t/we-want-to-utilize-create-or-replace-external-function-to-call-a-rest-api/4858/6 "2022-08-12T13:54:58Z")

</div>

Hi Maria , please respond. A faster reply would be really apriciated.

---

<div class="post-metadata">

**Author:** ![prakash.n.gour](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/p/bb73d2/32.png) [@prakash.n.gour](https://www.singlestore.com/forum/u/prakash.n.gour)\
**Post date:** [August 12, 2022, 1:55pm UTC](https://www.singlestore.com/forum/t/we-want-to-utilize-create-or-replace-external-function-to-call-a-rest-api/4858/7 "2022-08-12T13:55:36Z")

</div>

I see below when I executing like below

cmd\>docker exec -it singlestore-ciab memsql -p  
Enter password:  
Welcome to the MySQL monitor. Commands end with ; or \g.  
Your MySQL connection id is 504  
**Server version: 5.7.32 MemSQL** source distribution (compatible; MySQL Enterprise & MySQL Commercial)

Also in other environment we have - DB version is : **7.5.18**

Currently I m trying in 5.7.32

---

<div class="post-metadata">

**Author:** ![prakash.n.gour](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/p/bb73d2/32.png) [@prakash.n.gour](https://www.singlestore.com/forum/u/prakash.n.gour)\
**Post date:** [August 15, 2022, 4:18pm UTC](https://www.singlestore.com/forum/t/we-want-to-utilize-create-or-replace-external-function-to-call-a-rest-api/4858/8 "2022-08-15T16:18:53Z")

</div>

> [@prakash.n.gour](#):
>
> please respond. A faster reply would be really apriciated.

Hi Maria please respond

---

<div class="post-metadata">

**Author:** ![MariaSilverhardt](https://www.singlestore.com/forum/user_avatar/www.singlestore.com/mariasilverhardt/32/828_2.png) [@MariaSilverhardt](https://www.singlestore.com/forum/u/MariaSilverhardt)\
**Post date:** [August 16, 2022, 5:56pm UTC](https://www.singlestore.com/forum/t/we-want-to-utilize-create-or-replace-external-function-to-call-a-rest-api/4858/9 "2022-08-16T17:56:27Z")

</div>

Hi Prakash! Thanks for your patience. I was able to get some advice from the support team and have included it below.

Because it looks like you are looking at the SingleStoreDB Cloud docs, while running SingleStoreDB On-Premises - the team has suggested this link to our SingleStoreDB [documentation](https://docs.singlestore.com/db/v7.8/en/introduction/singlestore-documentation.html?action=version-change).

From here you can filter for the version you are running and to get a better understanding of your environments functionality.

In this particular case with the `CREATE [OR REPLACE] EXTERNAL FUNCTION` for SingleStoreDB On-Premises - this feature is not available until version 7.6. The associated docs are [linked here](https://docs.singlestore.com/db/v7.6/en/reference/sql-reference/procedural-sql-reference/create--or-replace--external-function.html).

As this feature is unavailable in 7.5, could you please try to upgrade the environment to at least 7.6 to get access?

Looking forward to hearing this resolved your issue. 🙏

---

<div class="post-metadata">

**Author:** ![prakash.n.gour](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/p/bb73d2/32.png) [@prakash.n.gour](https://www.singlestore.com/forum/u/prakash.n.gour)\
**Post date:** [August 23, 2022, 5:06pm UTC](https://www.singlestore.com/forum/t/we-want-to-utilize-create-or-replace-external-function-to-call-a-rest-api/4858/10 "2022-08-23T17:06:14Z")

</div>

Hi Maria,

I have 7.8 version docker image install now. but I m not able to use [CREATE [OR REPLACE] EXTERNAL FUNCTION feature to call a REST API hosted outside of memsql. I created the function and when calling the function I m getting -

- ERROR 2576 UNKNOWN\_ERR\_CODE: External function runtime failure: Couldn’t connect to server

Attached code snippet of create function and api call.

 ![image](https://forum-prod-assets20231213123829991800000001.s3.dualstack.us-east-1.amazonaws.com/original/2X/1/1b840aefa15e298bb303a5e8dcdb4dda66fe5fd4.png)

Please note -  
We are using in-premises db  
I testing feature locally - API up and running locally , memsql setup locally.

Looking forward for response.  
Thanks.

---

<div class="post-metadata">

**Author:** ![arnaud](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/a/e8c25b/32.png) [@arnaud](https://www.singlestore.com/forum/u/arnaud)\
**Post date:** [August 24, 2022, 11:30pm UTC](https://www.singlestore.com/forum/t/we-want-to-utilize-create-or-replace-external-function-to-call-a-rest-api/4858/11 "2022-08-24T23:30:57Z")

</div>

Have you looked into this: [GitHub - memsql/deployment-docker: This repository contains our official deployment Docker images for various products.](https://github.com/memsql/deployment-docker) ? We will add this section into our documentation.

The [HTTP API](https://docs.singlestore.com/db/latest/en/reference/http-api.html) and [External Functions](https://docs.singlestore.com/db/latest/en/reference/sql-reference/procedural-sql-reference/create--or-replace--external-function.html) features can be enabled when you create the container via passing environment variables.

**HTTP API:**

Add the following flags to your `docker run` command:

-e HTTP\_API=ON -p 9000:9000

By default, the HTTP API runs on port 9000. If you want to use a different port you can instead run:

-e HTTP\_API=ON -e HTTP\_API\_PORT=$PORT -p $PORT:$PORT

**External Functions:**

Add the following flag to your `docker run` command:

-e EXTERNAL\_FUNCTIONS=ON

---

<div class="post-metadata">

**Author:** ![prakash.n.gour](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/p/bb73d2/32.png) [@prakash.n.gour](https://www.singlestore.com/forum/u/prakash.n.gour)\
**Post date:** [August 25, 2022, 9:53am UTC](https://www.singlestore.com/forum/t/we-want-to-utilize-create-or-replace-external-function-to-call-a-rest-api/4858/12 "2022-08-25T09:53:44Z")

</div>

Hi [arnaud](https://www.singlestore.com/forum/u/arnaud),  
I think the things are getting confusing for me now like what is external function vs calling HTTP rest api. Let me rephrase it please-

We have SingleStoredb-studio version 7.8 docker image db is in-primises. In this SingleStoreDB we have some stored procedures written which contains the pipeline which consume the data from a topic.

Similarly what I want is - there is a RestAPI as well which is hosted on tomcat server i.e like hosted somewhere else which takes some input and then calls to some tables and return the response. we have all the details like endpoint url token generator and all and we are like calling the API from postman.

Similarly we want to call this Rest API from singleStoreBD store procedure to fetch some data like and want to utilize RestAPI response .

For that I wrote the above code I might be wrong in understand what CREATE [OR REPLACE] EXTERNAL FUNCTION is for.

Now please let me know if this is possible form SingleStoreDB or not? Like do we need to create external function or we can directly call the API. If possible what all flag/ settings we needs to do and how to call the RestAPI (steps to call the API)

Also which version of singlestoredb-server and singlestoredb-studio support this feature.

Thanks

---

<div class="post-metadata">

**Author:** ![arnaud](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/a/e8c25b/32.png) [@arnaud](https://www.singlestore.com/forum/u/arnaud)\
**Post date:** [August 25, 2022, 3:04pm UTC](https://www.singlestore.com/forum/t/we-want-to-utilize-create-or-replace-external-function-to-call-a-rest-api/4858/13 "2022-08-25T15:04:45Z")

</div>

Have you tried installing your image with that command? -e HTTP\_API=ON -p 9000:9000

I think that what you have started is the correct way to use that function. I would like to see if you still get the same error message when you have added the command.

---

<div class="post-metadata">

**Author:** ![prakash.n.gour](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/p/bb73d2/32.png) [@prakash.n.gour](https://www.singlestore.com/forum/u/prakash.n.gour)\
**Post date:** [August 25, 2022, 6:03pm UTC](https://www.singlestore.com/forum/t/we-want-to-utilize-create-or-replace-external-function-to-call-a-rest-api/4858/14 "2022-08-25T18:03:27Z")

</div>

> [@arnaud](#):
>
> -e HTTP\_API=ON -p 9000:9000

Hi [arnaud](https://www.singlestore.com/forum/u/arnaud)  
First thank you for quick response really appreciated.

I tried all like what you have been suggesting but still getting same error.  
Bellow is the container command I run and have added like you suggested please check if command looks good.

docker run -i --init --name singlestore-ciab -v singlestore-ciab-data:/var/lib/memsql -e HTTP\_API=ON -p 9000:9000 -e LICENSE\_KEY=$LICENSE\_KEY -e ROOT\_PASSWORD=$ROOT\_PASSWORD -p 3306:3306 -p 8080:8080 {proxy}/singlestore/cluster-in-a-box

---

<div class="post-metadata">

**Author:** ![arnaud](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/a/e8c25b/32.png) [@arnaud](https://www.singlestore.com/forum/u/arnaud)\
**Post date:** [August 25, 2022, 10:12pm UTC](https://www.singlestore.com/forum/t/we-want-to-utilize-create-or-replace-external-function-to-call-a-rest-api/4858/15 "2022-08-25T22:12:59Z")

</div>

To help you further, we would have to get more details in being able to repro those steps (I have tried to repo but I cannot connect to your URL and you probably don’t want to give me the credentials and configs on the forum).

Can you create a support ticket to be able to share more confidential information to repro your issue?
