Developer portal is not returning correct response from API

Hi Team,

I created a API Proxy, and i tested the same it is working as expected but same proxy i included in product and same added in developer portal.

When i execute APIs in Developer portal it is always giving 200 response irrespective of input parameter with below random html response and not giving expected response. Request you to kindly let me know how to fix this.

<!doctype html>
<html>
<head>
<meta charset="utf-8">

<!-- Ensure mobile displays do not scale down content -->
<meta name="viewport" content="width=device-width,initial-scale=1">

<!-- Default to blank favicon. Overwritten by real favicon if present -->
<link id="favicon" rel="icon" href="data:;base64,iVBORw0KGgo=">

<title></title>
<base href="/">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

<script>
/**
* Creates, kicks off, and returns an HTTP GET request
* @Former Community Member url where to send the request
* @Former Community Member onCompletion callback to execute when the request is complete. defaults to no-op
* @return {XMLHttpRequest}
*/
function getRequest(url, onCompletion = () => {}) {
const req = new XMLHttpRequest();
req.open('GET', url);
req.onreadystatechange = () => {
if (req.readyState === XMLHttpRequest.DONE) {
onCompletion(req);
}
}
req.send()
return req;
}

getRequest('/siteid', req => {
const siteId = req.responseText;
const baseUrl = '/portals/api/sites/' + siteId + '/liveportal/';
window.preloadRequests = {
SITE_MAP: getRequest(baseUrl + 'sitemap'),
MENUS: getRequest(baseUrl + 'menus'),
};
});
</script>
</head>
<body>
<app></app>
<script src="/js/runtime.5d5a916a16a0bf4f7725.js" defer></script><script src="/js/polyfills.7c8f9aca9ee2336e0365.js" defer></script><script src="/js/main.860d5af4e81794c26be5.js" defer></script></body>
</html>

0 5 350
5 REPLIES 5

I think you are saying that you are using the "interactive documentation", from within the developer portal, and you are not seeing the results you expect.

If what you have posted there is an example response you are seeing when you invoke the API Proxy from within the Developer portal, then.... I think your API request outbound from the developer portal is not reaching the API proxy. It's instead being handled by the developer portal itself. 

So, check your endpoints.

Usually the endpoint is defined by the OpenAPI Spec.   

openapi: 3.0.0
info:
  version: 1.0.0
  title: Whatever
  description: Sed commodo euismod libero, sit amet lobortis eros euismod ac.  
  contact:
    name: API Support
    url: http://www.example.com/support
    email: go@example.com
servers:
  - url: 'https://yourendpoint.com'
....

 

The server URL there.... is the thing the interactive documentation will invoke.  Your OpenAPI Spec is pointing toward the developer portal. Or, perhaps the spec has no URL at all, and the request is being sent back to the serving origin (which again, is the developer portal). 

 

 

Thank You @dchiesa1 , I did the changes as you suggest but after that I am getting different error like below.

"An unknown error occurred while making the request. Please verify your connection and try again. If you continue to experience issues please contact support".

since I am new to Apigee, not getting where exactly to check connection(API proxy working as expected but getting error in portal), request you to please suggest me on this.

Likely this is a CORS error.  Your API needs to support CORS in order to allow invocation from the developer portal. You can search here (on community) for CORS , to find some assistance on that. And also here's a screencast I produced recently on that issue. https://youtu.be/OHbuqW_1fP0

@Marsh  do you know of a quick-and-easy how-to video showing how to load a spec into the developer portal and be able to invoke the API endpoint successfully?

I don't have a great video to recommend--there are a number of moving parts here, so I'm not sure a video of that will address the root cause.

First thing I'd recommend is validating that the proxy is in fact returning the response you expect, (e.g. with cURL) in order to confirm that your API is functional. Next, you might validate that CORS is working as expected, so using a tool like SmartDocs in a portal might help, but just to be sure, you might also check another documentation rendering tool like Swagger UI. 

yes - good idea!

Invoke the API via cURL to verify that it's doing what you think it should be doing. You can also try using a tool like Postman. Neither cURL nor Postman (nor other tools that run outside the browser, for that matter) will be affected by the CORS issue.  CORS is relevant only when code running within a web browser invokes an api endpoint that is not the same as the origin server (the website you loaded the page from).  That IS the case when using a developer portal, and an API proxy managed by Apigee.