External database

Hi guys:

I need to import an external database from a twin website. So I create my http-js in the site A and the query works fine if I use the url. You can test it: https://www.medidata-bsl.net/_functions/myFunction
The problem is when I try to create the database in the site B. What am doing is:

But when I clic on Add button I got this error

PLEASE HELP ME!

Some questions…

  • What do you mean by Site A and Site B? What are the URLs of both sites? I only see one site: https://www.medidata-bsl.net

  • What do you mean by an “external collection”?

  • What do you mean by a “namespace”?

  • What Add button are you clicking on? Where is this button?

HI!!! Thanks for your response (im a big fan of yours).

I´ll post a video explainning myself

Your questions:

Site A: www.medidata-bsl.net
Site B: www.sitel-bsl.com

“External collection” is an external database

“Namespace” is the word it appears in the error sign I posted in the picture

The “Add” button is the wix button in the window “Add an external collection”

Now I understand. From what I can see in your video, you are not exposing an external database in Site A, rather you are exposing an API to be used by another site (Site B). The code in the http-functions.js file exposes the API in Site A to be used by Site B.

When you try to add an external database collection in Site B, it fails since you also need an external database adapter . For further information, see the External Database documentation .

What you really want is for Site B to consume the API exposed in Site A. For that, you need to relate to Site A as an “external service”. See Corvid: Accessing Third-Party Services with the Fetch API for information on how to interface with the service exposed in Site A.

To see a working example of two sites working together like your Site A and Site B, see the MyApi and MyApiClient example which shows how to expose and access external APIs.

Thanks again. I open the example sites you posted and what I see is in the Recepies site you have:

serviceModule.jws
http-functions.jw

If I tried to create the external collection in the API client site, appears the same error.

What am I doing wrong :disappointed_relieved:

You do not want to use an external database in the client site (Site B). In fact, the client site has no database. Instead, it accesses the database in the third party service site (Site A) by using the functions in serviceModule.jws.

Run the two example sites: MyApi and MyApiClient and you will see how it works.

Thanks for your patience. Look what I have when I publish them:

https://danieltalero78.wixsite.com/mysite-2
https://danieltalero78.wixsite.com/mysite-3

Nothing happens :sleepy:

Thanks again for your time

In the client site, you need to set the baseUrl to point to the API exposed in the server site. Replace API_BASE_URL in the following line of code to the URL that will point to the endpoints in the server site.

const baseUrl = "API_BASE_URL";

To determine the correct API_BASE_URL, use the rules that appear before the above line of code:

//////////////////////////////////////
// Clients consume HTTP functions by reaching endpoints with the following patterns.
//
// ** Production endpoints
//   * Premium site:
//     https://www.{user_domain}/_functions/<functionName>
//   * Free sites:
//     https://{user_name}.wixsite.com/{site_name}/_functions/<functionName>
//
// ** Test endpoints
//   * Premium sites:
//     https://www.{user_domain}/_functions-dev/<functionName>
//   * Free sites:
//     https://{user_name}.wixsite.com/{site_name}/_functions-dev/<functionName>
//
//////////////////////////////////////

Look what I did. Still not working.

(seriously thanks for teaching me)

Please share code in a code block (not a video) as stated in the Forum Guidelines.

We are unable to debug your site for you. You will need to carefully read Corvid: Exposing a Site API with HTTP Functions , watch the video, and use the example that I linked to. The example works, and has worked fine for many users. You just need to configure it correctly according to the docs.

What Im doing
MyApiClient site: Code in serviceModule.jws

import { fetch } from ‘wix-fetch’ ;
import wixUsers from ‘wix-users-backend’ ;

//////////////////////////////////////
// Clients consume HTTP functions by reaching endpoints with the following patterns.
/

const baseUrl = “https://danieltalero78.wixsite.com/mysite-4/_functions/recipe” ; //this is the url from MyAPI site

export function getRecipes(premium) {
const url = baseUrl + “recipes” ;

Your problem might just be a missing slash at the end of the URL, and that you should not include a function name. The URL is the base URL.

" https://danieltalero78.wixsite.com/mysite-4/_functions/ "

IT WORKS!! (was the missing slash). Thank you so much!

So to finally clarify:

You need 3 sites:

  1. The client

  2. The Appi

  3. The site where the database is

Thank you so much for your patience and your time. This example really really help me to improve the project im doing

You need two sites. The client site, and the API site (which is where the database is).

The example has three sites: a client, an API, and a combination of both. You don’t need to worry about the combination site - it’s just for the example and makes it easier to debug (for me at least).

God bless you. Thanks for your help

:beers:

Hi again! Last question:

What if I want to add a new record to the database from the API client site to the API Site. Is that possible?

Thanks again