Error connecting to external API with Wappler

#1

Wappler Version : 1.9.7
Operating System : Windows 10

Expected behavior

What do you think should happen?

It should make a connection to this API.

Actual behavior

What actually happens?

I get an error: Authorization required

How to reproduce

  1. I tested the API connection in Postman first, no problems there getting a response.

  2. I then entered the exact same information (URL, headers etc) in to Wappler, and then did a fetch. No problems so far, fetch worked fine.

  3. When trying to execute the server connect on the live site, I’m getting an error when checking the network tab within ‘inspect element’ in Chrome.

I have contacted the application where I’m connecting to, but their logs say they haven’t received any requests, and so it must be on our server side. I can connect to the API with Postman, just not with Wappler somehow.

#2

Hi Nevil,
Are you sure your Authorization header value is actually inserted in the server action (not only where you fetch data) and also is it valid?

#3

Yes it seems that the most recent version of wappler automatically retrieves the data of the headers section to the fetch window, so I didn’t change anything there. I didn’t manually fill in that field in fetch.

And so when the fetch works fine, it’s strange that the actual live version doesn’t work. This is btw the only api that has this, I’ve tried several other api’s and they all work fine.

#4

Can you try removing the authorization header, add it again, save the server action and upload it to your server - does it make any difference?

#5

No difference :cry: should I send an error report?

#6

@Teodor is this now a known bug on your side, or do you need anything from me?

#7

This doesn’t really look like a bug to me.
Can you share some link where i can inspect what’s going on maybe?

#8

Yes: http://api.naturalheroes.nl/data/sync.php

Click the button “inventory planner”

#9

My guess is that the value for the authorization header is incorrect, did you put quotes around the value?

#10

I have tried double and single quotes in the value field just now, makes no difference.

The odd thing is that fetch API schema works fine. Also connecting with the exact same credentials using Postman works fine.

#11

@patrick any other idea what we can do?

#12

You can test with https://requestinspector.com. Just generate an hook there and change the url of your API action, then you can see what the actual data is that is send to the endpoint.

#13

Yes I know this, but that isn’t solving the problem.

Knipsel

This is all correct.

Again, it works fine when I use postman, just not in Wappler. I’m pretty sure I’ve done everything like I’m supposed to. Is there anything you can check on your side?

#14

Is it possible that the api checks more then only the authorization header, maybe it doesn’t like the user-agent or only allows ajax requests.

#15

Yes I had already checked this, they only require application/json, and the account & authorization headers.

Again, using the exact same headers in Postman works fine.

#16

Did you test the server connect action on a different server, like a local wamp/mamp server?

split this topic #17

5 posts were split to a new topic: Error using API Data Source

#18

I just did test this from another server, got the same problem. But then I contacted the developer of this API, they told me they received the header name in lower case, while they required it to be with the first letter as a capital letter. They corrected this on their side, and then I could connect again.

So my question is, does Wappler convert all header names/values to lower case?

assigned patrick #19
#20

Good that you figured out what was wrong and that they could solve that in the API. The headers are normally not case sensitive, Wappler doesn’t convert them to lowercase, the problem is the HTML DOM. We use standard HTML DOM in App Connect, so components are just tags and attributes, problem is that the DOM is not case sensitive, and it returns all attribute names in lowercase. That is why it was converted, we will have a look on how to improve this.

1 Like