cancel
Showing results for 
Search instead for 
Did you mean: 

403 Error when running 'Try It Out'

Highlighted
Frequent Visitor

403 Error when running 'Try It Out'

Hello! I'm new to Swagger and to APIs in general, and I am having trouble getting the Try It Out feature to work on a small sample API that I made on my local machine. Of course, I am running it on localhost:8080, which is probably the crux of the issue as per this thread from 2018: https://community.smartbear.com/t5/SwaggerHub/Can-I-use-localhost-as-host-in-swaggerhub/td-p/160421

The API runs perfectly fine, and I get responsive outputs in both Postman and Swagger Inspector, as depicted here:

samuel_meek_0-1601662466530.png

 

However, when I go to run a 'Try It Out' test on that same customers-GET endpoint, for example, I am persistently greeted by either an HTTP 403 error or a TypeError: Failed to fetch:

samuel_meek_1-1601662667570.png

The try-it test above was run in the standalone SwaggerUI at

http://petstore.swagger.io/?url=https://api.swaggerhub.com/apis/smeek333/customer-log/1.0.0

and I put in the following CORS code, all as instructed in the resolution in the thread linked to above:

 
 
     app.use(function(req, res, next) {
         res.header("Access-Control-Allow-Origin", "petstore.swagger.io"); // update to match the domain you will make the request from
         res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
         next();
       });
 
 
 
What am I missing? Did I put the proper domain in the red code snippet above? Please find my API's script.js and my .yaml files attached for reference.
 
 
New Here?
Join us and watch the welcome video:
Top Kudoed Authors