API problems on the server side

Hi all,

I had a working client side API call to return some data - worked perfectly, but I want to conceal the source so implemented the same call on the server side, it’s an exact replica (and I’ve also tried all kinds of variations) but I keep getting the following error:

stack: "TypeError: data should be a string, Buffer or Uint8Array↵

Noting I can define the schema fine on the server side when using the URL and the query parameter that would be passed via the form - but when I try to use dynamic parameter value e.g. {{$_POST.profile}} then it fails.

Not sure if it’s a bug or if I’m just doing something wrong - has anyone experienced the above, and was able to solve it?

@Teodor - tagging this as I need your expertise to define if this is a bug or user error here. There are lots of strange things going on here.

It seems to store the previous input data or queries even when there are none and then apends them to the URL - if I use the exact URL path i’m trying to generate in the client side - it works fine, if I ‘define api schema’ on the server side it works fine - the moment I try to use the input data / query inputs it fails. Running the API call in a browser also works perfectly fine. Can you provide some support here?

If I turn this server connect form into a API form with exactly the same call information - it works perfectly.

Can you share some screenshots of what is defined in the Server Connect API action and where do you see the error?

Server side defined schema - you can see this working fine:

How I have setup the inputs (noting these work fine with Form API)
Screen Shot 2020-08-18 at 10.59.31 am
You can see that Input Data remains highlighted, even when there are no entries there.

URL it generates: http://localhost:8100/api/recruiterly_platform/PeopleDataTool/quickLookupLinkedIn?profile=www.linkedin.com%2Fin%2Fseanthorneprofile=www.linkedin.com%2Fin%2Fseanthorne&= - you can see it has apended the profile URL twice - when I have it implemented only once in the query parameters.

In addition, this is the error I get:

  1. message: “data should be a string, Buffer or Uint8Array”

Again, this setup works perfectly when just applying the correct query in browser, or as a form API or as a client side API action - it just doesn’t work via server connect to the workflow.

When I try the same call via API Form but use more than one input parameter - it also fails in the same way.

@Teodor any update/thoughts on this?

Where does it generate this URL? The url looks from the server connect action, not from the api endpoint. In the server connect action you use {{$_POST.profile}} while seeing the url you seem to pass the parameter in the query instead of a post.

Where exactly do you get this error, was it returned from the server connect call?

This is the url I see rendered in the network tab after attempting to make the call. I’m also using {{$_POST.profile}} for the query parameter.

The same, in the network tab.

What you see in the network tab is not the api call made by the server action, it is the call to the server action. How do you call the server action, probably not using a post?

appreciate your help here Patrick. I did notice online that this error: [quote=“mgaussie, post:4, topic:23795”]
message: “data should be a string, Buffer or Uint8Array”
[/quote] is actually a common one for NodeJS and there are various solutions on stack overflow.

However, this is what I’m doing - so I hope it’s just user error you can help me navigate.

We have an external API - which we use a GET call to match our input against their database and this returns information matching our GET Call input.

I’ve tried to do this via API Form, and SC. Ideally I build the API in SC so we are hiding the URL and we call our own Rest API that then calls their API to return the data.

This is the SC info:
Screen Shot 2020-08-19 at 9.12.15 am

Screen Shot 2020-08-19 at 9.12.44 am

(api key not shown for security reasons)
Screen Shot 2020-08-19 at 9.13.16 am

If i enter a profile in this post - it returns the correct info

If I then try to SC to this API Action - it fails, and as you can see from the above paths - it is apending the profile twice, when I am inputting only once.

When I try API Form instead I get the same issue or even just a ‘invalid api key’ even when I’m using the same one on the SC that works fine!

In addition, you can see in the UI here, I only have entries in ‘query’ yet input data is highlighted as if it’s stored previous data that was deleted - and seems it might be adding that to any query path:

Screen Shot 2020-08-19 at 9.23.02 am

Are you using a server connect form to post the profile variable to the server action? It looks like you are doing a get instead of a post, the profile should not be visible in the querystring.

Server Connect Form (Post):
Screen Shot 2020-08-19 at 9.52.05 am

Api Action:
Screen Shot 2020-08-19 at 9.52.40 am

Doesn’t even pass the data through doing it this way - returns an empty call api error from the provider.

I have just tried another call (there are 3 different ways to enrich data via this API we are using).

SC form (POST) two inputs.
SC Action - call the API URL with a GET
in Query - using both fields as POST from the form (that have been correctly mapped by importing the fields from the form itself).

I get this error still and again in network tab:

  1. message: “data should be a string, Buffer or Uint8Array”

NEW:
I have now also tried removing ‘query’ and instead using input data
Screen Shot 2020-08-19 at 10.05.05 am

Again you can see the blue query remains as if it’s storing it, and not recognizing it’s been deleted.

And with this call - I simply get the same error:

  1. message: “data should be a string, Buffer or Uint8Array”

Please help @patrick - this is such a basic API call.

Do you run the NodeJS server on localhost? If it is running the server directly on port 3000 then you should see errors in the console within Wappler, if you are running it in Docker then you have to check the log.

image

I want to know which file/line throws the error that you are getting.

Did you also test with a static value instead of the {{$_POST.profile}} expression?

static value within the ‘Define API Schema’ works fine. but not in the query value itself in Wappler.

I am NodeJS on docker.

I have clicked the view logs - but nothing happens - please advise where I would get to these

Got it in Docker:

server-connect:router Serving serverConnect /api/recruiterly_platform/PeopleDataTool/quickLookupLinkedIn +0ms

server-connect:server Got error? TypeError: data should be a string, Buffer or Uint8Array

server-connect:server at RedirectableRequest.write (/opt/node_app/node_modules/follow-redirects/index.js:73:11)

server-connect:server at /opt/node_app/lib/modules/api.js:92:17

server-connect:server at new Promise (<anonymous>)

server-connect:server at App.send (/opt/node_app/lib/modules/api.js:66:16)

server-connect:server at App._exec (/opt/node_app/lib/core/app.js:251:57)

server-connect:server at App.exec (/opt/node_app/lib/core/app.js:204:20)

server-connect:server at App.define (/opt/node_app/lib/core/app.js:187:20)

server-connect:server at processTicksAndRejections (internal/process/task_queues.js:97:5) +0ms

And again on another API call:

server-connect:router Serving serverConnect /api/recruiterly_platform/PeopleDataTool/PDTquery +2ms

server-connect:server Got error? TypeError: data should be a string, Buffer or Uint8Array

server-connect:server at RedirectableRequest.write (/opt/node_app/node_modules/follow-redirects/index.js:73:11)

server-connect:server at /opt/node_app/lib/modules/api.js:92:17

server-connect:server at new Promise (<anonymous>)

server-connect:server at App.send (/opt/node_app/lib/modules/api.js:66:16)

server-connect:server at App._exec (/opt/node_app/lib/core/app.js:251:57)

server-connect:server at App.exec (/opt/node_app/lib/core/app.js:204:20)

server-connect:server at App.define (/opt/node_app/lib/core/app.js:187:20)

server-connect:server at processTicksAndRejections (internal/process/task_queues.js:97:5) +0ms

Thanks, that should help me with finding the problem. Seems the error is thrown in the follow-redirects module, will investigate it.

Thank you - I assume this would be fairly high priority - as it seems no api’s are working (certainly in my case) and is grinding this project to a hault at the moment.

Here a small update, place it in lib/modules.

api.zip (1.2 KB)