Unable to retrieve data from client via httpRequest
I have a client that no longer wants to use sftp to transmit their data file to me. Instead they want me to pick it up via a web service.
Email from client:
Here is the postman collection and mocking service to start your development. The API has only one URI parameter {id} for which you need to pass UniqueIdentifier(will let you know exact value later).
attachments: ssrg-exp-api.postman_collection.json, IB006_Response.json
- The attachments the client provided can be found in the attached pdf KCS API documents.pdf
When going to the link supplied via a web browser ( {id} should be part of the link ), I see the results desired:
But when I use my code from within Cache, I'm getting html code:
SRG>d GET^KCSAPI
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!-- Added IE-Edge to fix login rendering in Studio -->
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<title>Anypoint Platform</title>
<link rel="shortcut icon" href="https://cdn.anypoint.mulesoft.com/core/v1/icons/favicon.ico">
<!-- Preload the icons for the navbar to improve render speed and ensure that they are properly cached. -->
<link rel="prefetch" href="/icons/sprite-4.15.1.svg" type="image/svg+xml">
<!-- Preload the font for the navbar so that it renders immediately on login -->
<link rel="preload" href="https://cdn.anypoint.mulesoft.com/artifacts/anypoint-styles/fonts/DINPro..." as="font" crossorigin>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="referrer" content="origin">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<link href="https://cdn.anypoint.mulesoft.com/artifacts/anypoint-platform-ui/app/sty..." rel="stylesheet">
<meta name="ui-version" content="v0.22.0-1-g3896105">
</head>
<body class="anypoint-styles">
<script>
window.Anypoint = {
deployment: 'cloud'
};
if (window.Anypoint.deployment === 'cloud') {
// We only load analytics for the cloud environment, not for PCE
const analyticsScript = document.createElement('script');
analyticsScript.src = '/shared/analytics.min.js';
document.body.appendChild(analyticsScript);
}
</script>
<div id="shellRoot"></div>
<!-- core-js polyfills for IE11 support -->
<script src="https://cdn.anypoint.mulesoft.com/artifacts/anypoint-platform-ui/app/cor..."></script>
<script src="https://cdn.anypoint.mulesoft.com/artifacts/anypoint-platform-ui/app/rea..."></script>
<script src="https://cdn.anypoint.mulesoft.com/artifacts/anypoint-platform-ui/app/rea..."></script>
<script src="/shared/anypoint-navbar.js"></script>
<script type="text/javascript" src="https://cdn.anypoint.mulesoft.com/artifacts/anypoint-platform-ui/app/bun..."></script>
</body>
</html>
Cache code:
K S $ZT="^%ET"
s id="{id}"
set httprequest = ##class(%Net.HttpRequest).%New()
set httprequest.SSLConfiguration = "HTTPS"
set httprequest.Server = "www.anypoint.mulesoft.com"
set httprequest.Location = "/mocking/api/v1/links/03a74865-d7fb-4318-a310-7ad2b95361f6/v1/receivables/"_id
set httprequest.Https = 1
set httprequest.ContentType="json"
set sc=httprequest.SetHeader("Connection","close")
set status = httprequest.Get("/") ;returns html page
//s status = httprequest.Get("") ;returns msg: {"code":"INVALID_RESPONSE_ACCEPT_HEADER","message":"Error trying to find response for invalid media type"}
//set status = httprequest.Get("anypoint.mulesoft.com/mocking/api/v1/links/03a74865-d7fb-4318-a310-7ad2b95361f6/v1/receivables/9") ;commented out httprequest.Location - returns same html page
if status {
s response=httprequest.HttpResponse //IS JUST RETURNING PAGE
do response.Data.Rewind()
do {
write response.Data.Read()
} while 'response.Data.AtEnd
}
quit
Can someone point me in the right direction and/or let me know where the error lies in my code. Why am I not able to pull the desired results? (as shown in the screen snippet).