Unsupported content type in serverless app using Request API

Hi Guys,

I tried to read OAuth access token in serverless app using Request API.

Here is tried code:

var headers = {"Content-Type": "application/json"};
var options = {
     headers: headers,
     isOAuth: true
};

$request.get(`https://graph.facebook.com/me?access_token=<%= access_token %>`, options)
       .then(function(data) {
           // success
           console.log("oauth "+data);
       }, function(err) {
           // failure
           console.log(err);
     });

Here is the returned error:

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

Thank you.

Hi,
Can you please try the following snippet

const options = {
  headers: {
    test: "<%= oauth_iparams.client_id  %>"
  },
  isOAuth: true
};

In serverless app

My error is: { status: 415,
headers: {},
response: ‘Unsupported content type’,
errorSource: ‘APP’,
attempts: 1 }

Here is tried code(Just try to fetch image data):

$request.get("https://i.imgur.com/lcB62xb.jpg")
    .done(function(data) {
      console.log(data);
    })
    .fail(function(err) {
      console.log(err);
    });

This is the image URL: https://i.imgur.com/lcB62xb.jpg

can you explain what is my mistake.

The response is an image with content-type: image/jpeg which is not supported by the serverless app.

1 Like

Thanks for your response @ManiDeepak_Vandrangi,

I got the solution

$request package has followed by syntax format of json in header,

Reference: marketplace-sample-apps/server.js at master · freshworks/marketplace-sample-apps · GitHub.