Kelly Blake · Jul 6

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).{id}

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:

<!DOCTYPE html>
<html lang="en">
    <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="">

    <!-- 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="" 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="" rel="stylesheet">
    <meta name="ui-version" content="v0.22.0-1-g3896105">
  <body class="anypoint-styles">
      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';
    <div id="shellRoot"></div>

    <!-- core-js polyfills for IE11 support -->
    <script src=""></script>
    <script src=""></script>
    <script src=""></script>
    <script src="/shared/anypoint-navbar.js"></script>
    <script type="text/javascript" src=""></script>

Cache code:


 K  $ZT="^%ET"   
  set httprequest = ##class(%Net.HttpRequest).%New()
 set httprequest.SSLConfiguration = "HTTPS"
  set httprequest.Server = ""
  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("") ;commented out httprequest.Location - returns same html page
if status {
response=httprequest.HttpResponse //IS JUST RETURNING PAGE
     do response.Data.Rewind()
     do {
     write response.Data.Read()
     while 'response.Data.AtEnd 

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).

Product version: Caché 2015.1
$ZV: Cache for UNIX (Red Hat Enterprise Linux for x86-64) 2015.2.3 (Build 855_0_17370) Thu Jun 1 2017 18:47:29 EDT
3 0 7 79
Log in or sign up to continue

Try this way

K  $ZT="^%ET"   
  set httprequest = ##class(%Net.HttpRequest).%New()
 set httprequest.SSLConfiguration = "HTTPS"
  set httprequest.Server = "" /// CHANGED
 set httprequest.Https = 1
 set httprequest.ContentType="json"
set sc=httprequest.SetHeader("Connection","close")
set status = httprequest.Get("/mocking/api/v1/links/03a74865-d7fb-4318-a310-7ad2b95361f6/v1/receivables/"_id") /// CHANGED
if status {
response=httprequest.HttpResponse //IS JUST RETURNING PAGE
     do response.Data.Rewind()
     do {
     write response.Data.Read()
     while 'response.Data.AtEnd 

 That gives me the following:

{"code":"INVALID_RESPONSE_ACCEPT_HEADER","message":"Error trying to find response for invalid media type"}

I added an output of the headers:

HTTP/1.1 415 Unsupported Media Type
CONTENT-TYPE: application/json
DATE: Wed, 07 Jul 2021 15:38:26 GMT
MS2-ERROR: MockRequestError
SERVER: nginx
STRICT-TRANSPORT-SECURITY: max-age=31536000; includeSubDomains
X-ENVOY-DECORATOR-OPERATION: service.mocking.svc.cluster.local:80/*
X-REQUEST-ID: 7deac252-b38a-430e-9931-e77a8b87bef2

Error has occurred <COMMAND> in SRG at 11:38 AM  Jul 07 2021
(now saving error/stack information)

Any documentation I can find containing this 'error' refers to making POSTs.  I'm doing a GET, so I'm completely baffled....

I think based on your error it doesn't like set httprequest.ContentType="json" Which your browser based version is probably not setting.

That wasn't it.  I have commented that line out completely, and I get the same error. (415 Unsupported Media type).

I also changed it from json to application/json (as indicated in the headers retrieved from the server) - Still the same error.

First the content type is not correct.  This should be application/json.  Next I would add the following statement

do httprequest.SetHeader("Accept","application/json")

This tells the request what type of response your application will accept.  The default is text/html I believe which can't be supplied by the api.

Thank you so much!!!  Setting the header accept was what was needed.