Swagger spec error - TypeError: Failed to fetch

Not applicable

So my api is working but anyway i try to test it through the swagger spec, i get the error:

TypeError: Failed to fetch

But the url is correct, and the keys are correct - and the request url etc matches what works in the browser.

i have seen this is often associated with CORS not being set, but my proxy has CORS set, and the url passes independent CORS checks

More critically, the docs which then link through to the portal, also do not work, in that any request to test an end point returns an error:

Unknown Status

{ "isTrusted": true }

I have also seen references to a preflight check of CORS being the cause, so looked at trialling from the docs

https://docs.apigee.com/api-platform/develop/adding-cors-support-api-proxy

But the section on preflight checks dont appear to have made any difference.

Am i missing something?

Many thanks

1 8 52.8K
8 REPLIES 8

This is usually due to either the CORS issue you mentioned, or an http/https mismatch. My guess is that your spec calls for http, but the portal is being served on https. Try changing to https.

Thanks, but spec set on https (as well as proxy)

This worked. Thanks

@James Askew

Have you tried running trace on your API? You should see a OPTIONS request which you will need to respond to with a 200 and the correct headers (e.g. x-apikey) that your API is passing.

Hope that helps.

siddheshnaik
Participant II
@James Askew

Even I was having same issue.
200 responses were successfully reflecting in Swagger Document, but in error conditions it was giving undocumented TypeError: Failed to fetch error.

Issue is resolved on adding CORs in error flow like below:
<DefaultFaultRule name="PlatformFaults">

<Step> <Name>AM-AddCORS</Name> </Step>

<Step> <Name>RF-InternalError</Name> </Step>

</DefaultFaultRule>

I hope It will help you.
Thanks.

i too have a same problem.when i made a post request from swagger,options request is sent.@James Askew

In the "Access-Control-Allow-Headers", add "Authorization"

I was facing the same issue .you can try instead of using "https://localhost:5000" use "http://localhost:5000