API problems on the server side

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)

Thanks @patrick unfortunately didn’t solve the issue, now getting a different error:

  1. message: “Cannot use ‘in’ operator to search for ‘length’ in null”

Docker Log:
/api/recruiterly_platform/PeopleDataTool/quickLookupLinkedIn +2m

server-connect:server Got error? TypeError: Cannot use 'in' operator to search for 'length' in null

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

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) +2m

I don’t get the error when testing the api, seems to be something with the redirect module. Does the api endpoint do a redirect?

I have a new small update here for you to test.

api.zip (1.2 KB)

testing… this seems like it might have fixed it!

@patrick with additional testing, now on the F/E - I seem to have a strange issue with API Source / API Action components.

API Source can GET data, e.g. from the Google Places API. However, if I use the exact same setup for a API Action - the parameters do not appear in the schema and so it constantly tells me that the key is needed.

In fact when you create the query parameters and try to define schema, they do not appear at all.

API Source ‘Define Schema’
Screen Shot 2020-08-21 at 8.59.35 am

API Action ‘Define Schema’ - exact same setup as API Source:

You can see it’s empty.

If I do the same on the Server side - Api action - the query parameters appear in the ‘define schema’

I had to make several changes in the API for an other request. This changes how GET requests are done. Please check if it doesn’t break API call.

api.zip (1.1 KB)

This topic was automatically closed after 30 hours. New replies are no longer allowed.