+ Start a Discussion
surya7628@gmail.com Ksurya7628@gmail.com K 

I am getting the error like 415 while using the rest api post method for update the record in mongo db from salesforce

Hi All,
I need to update the record in mongo db,hear i have the mongo db record id in salesforce, based on that id i need to update the status from
(in process to completed) when ever user changed the status from 'in process' to 'completed' in salesforce.

I am getting the error like (DEBUG|ResponceSystem.HttpResponse[Status=Unsupported Media Type, StatusCode=415]),please suggest me.

i have used below code:

public class AuthCallout {
    String payLoad = 'slug={!order.Mongo_DB_Order_ID__c}&OrderStatus={!order.Staus}';

    public void basicAuthCallout(){
        HttpRequest req = new HttpRequest();
        HttpResponse res1 = http.send(req);
Prafull G.Prafull G.
You should set the appropriate content type or Accept type with request as per the mongolab api.

Try setting like this
req.setHeader('Content-Type', <value of content type supported by api i.e. application/json>);
req.setHeader('Accept', <value of accept type supported by api i.e. application/json>);

let us know if it helps.
surya7628@gmail.com Ksurya7628@gmail.com K
Hi Prafull,

I have tried the below code,i am getting the error like System.HttpResponse[Status=Unsupported Media Type, StatusCode=415],hear i am getting the responce in get method,now i am facing the issue with put method.can u suggest me

global class AuthCallout {
    static webservice void basicAuthCallout(id ordid,string status){
        order ord = [select id,status,Mongo_DB_Order_ID__c from order where id=:ordid limit 1];
        Http http = new Http();
        HttpRequest req = new HttpRequest();
        HTTPResponse res = http.send(req);
        fromJSON obj =new fromJSON();
        obj.OrderStatus =status;
        HttpRequest putReq = new HttpRequest();
        HTTPResponse putRes = http.send(putReq);
        system.debug('-----------------'+putRes );  

Below one is the record in mongo db :

    "_id": {
        "$oid": "56bd84d211576df406cce9bd"
    "slug": "56bd84d211576df406cce9bd",
    "SFID": "",
    "ITCSV": "",
    "ITReport": "",
    "NTCSV": "",
    "NTReport": "",
    "OrderStatus": "Completed",
    "OrderDate": {
        "$date": "2016-02-12T07:08:01.000Z"
    "ContactNumber": "987456321",
    "email": "test@test.com",
    "LenderBranchCode": "test",
    "OrderNumber": "new value",
    "LoanApplicantName": "test",
    "LoanRefNum": "Test3",
    "__v": 0

---------------->i have converted above record from json to apex

public class fromJSON{
    //public cls__id _id;  //when i try to save this class it is not allow to save for that i have changed this to [public clsid id] 
    public clsid id ;i am using this one insted of above public cls__id _id;
    public String slug;    //56bd84d211576df406cce9bd
    public String SFID;    //
    public String ITCSV;    //
    public String ITReport;    //
    public String NTCSV;    //
    public String NTReport;    //
    public String OrderStatus;    //Completed
    public cls_OrderDate OrderDate;
    public String ContactNumber;    //987456321
    public String email;    //test@test.com
    public String LenderBranchCode;    //test
    public String OrderNumber;    //new value
    public String LoanApplicantName;    //test
    public String LoanRefNum;    //Test3
    public Integer v;    //0
    //class cls__id {
        //public String $oid;    //56bd84d211576df406cce9bd
   // }
    class clsid {
        public String oid;    //56bd84d211576df406cce9bd
    class cls_OrderDate {
        public String $date;    //2016-02-12T07:08:01.000Z
    public static fromJSON parse(String json){
        return (fromJSON) System.JSON.deserialize(json, fromJSON.class);


And i am calling this class in after update trigger.


Prafull G.Prafull G.
For PUT method also, you have to specify accept or content type similar to GET.
Please try!