Unsupported content-type while calling an external API using request

I am using an external API in my App that sends a response with content-type application/rdsConnectComputer.v1+json

While hitting the API, I am getting the following error code:

{
    "status":415,
    "headers":{},
    "response":"Unsupported content type",
    "errorSource":"APP",
    "attempts":1
}

I can confirm that the API sends data correctly. While browsing about the error I came across that only application/json is supported by client.request. Am I doing something wrong or is there any work-around for receiving custom content types from APIs?

Code snippet for reference:

var apiUrl = serverHome + '/api/apiEndpoint/initiate';
var headers = {
  'Authorization': '<%= apikey %>',
  'Content-Type' : 'application/rdsConnectComputer.v1+json',
  'Accept' : 'application/rdsConnectionInfo.v1+json'
};
var bodyJson = {
  'name' : 'Desktop' ,
  'message' : message
};
var options = {
  headers: headers,
  body: JSON.stringify(bodyJson)
};
client.request.post(apiUrl, options).then(function (data) {
  var jsonData = JSON.parse(data.response);
  console.log(jsonDate.isSuccess);
});
1 Like

Hi @sanjay.sr,
Welcome to the Developer Community :tada:

Can you please share the API documentation for this endpoint so we can see if the content-type is a valid one.

I’m sorry, but there is no documentation as these are internal APIs of our product…

The following content-types are allowed for external APIs

  • application/json
  • application/jsonp
  • application/vnd.api+json
  • application/xml
  • text/plain
  • text/html
  • text/xml
  • text/javascript

Can you please use one of these content-types in the internal APIs?

We are unable to change the content-type of the APIs as they are used within the product and in other integrations too. Is there any other work-around for this purpose?

Can you please share the documentation on “application/rdsConnectComputer.v1+json” content-type? I am unable to find it online.

@ManiDeepak_Vandrangi Sorry for the delay in response, as mentioned previously, documentation for “application/rdsConnectComputer.v1+json” is not available as it is a self customized Media Type that resembles a JSON (hence +json). It is used as a part of a Jersey API in the annotations. We have multiple other similar content types that are used for multiple APIs

Some examples - Example 1 , Example 2

We won’t be able to change the content-type to any of the mentioned ones as it is a rigid standard for us.

We rarely support specific response types. Apps can bypass this restriction by using third party npm libraries to send HTTP/HTTPS requests. Are you facing any problems by using third party npm library?

@ManiDeepak_Vandrangi We haven’t used any 3rd party NPM yet, any examples I can look into in this specific regard?

Sure.
axios - npm is one library which may fit your use case.

Thanks a lot for your support! Will check it out

1 Like

Hey @ManiDeepak_Vandrangi , As discussed, I am able to use axios to initiate an API request from my app’s web client to our development server.

But in the App Guidelines it is mentioned that we should use only the Request API to perform any kind of external API calls. Doesn’t using axios override this security point?

Also while using axios I am able to see the request originates from *.cloudfront.net. Unfortunately we wouldn’t be able to allow CORS for any cloudfront domains. Kindly advise on the same.

1 Like

@sanjay.sr - I see you are trying to make API calls from frontend of the app. In that case, even the API calls made from ‘axios’ would fail as Browsers themselves block CORS. Which is why an client.request API is available for the apps to make requests from the frontend.

Now if client.request doesn’t support the requested the content type, we will need to see if there is a possibility to support application/rdsConnectComputer.v1+json. This might not be possible, but I could check from the team for an update.

That leaves the app to anyway rely on an NPM package to make the API call. This is possible using Server Method Invocation and NPM Packages. Nevertheless, the requests that your server would receive by using an NPM package would be from a dynamic IP. API calls from the backend can also be made by a equivalent variant of Request Method by

$request.get("URL", options)
  .then(
    function(data) {
      //handle "data"
      //"data" is a json string with status, headers, and response.
    },
    function(error) {
      //handle failure
    }
  );

API calls made from using Request Method would originate from specific IP ranges that you can whitelist. In your case requires external NPM package in backend to make the API call.

Edit 1: Note that SMI may have size restrictions upto 100kb

1 Like

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.