You need to sign in to do that
Don't have an account?

when I am making a callout in salesforce I am getting 404 not found, but i am getting the response in postman
I am trying to make a callout in salesforce , then I am getting response as 404 not found. when i am doing the same thing in Postman I am getting the response.
could any one suggest where i am going wrong.
here is my class:
public class housingcallout {
@future(callout=true)
public static void sendhousingCalloutREST(){
Housing_creds__c data = Housing_creds__c.getvalues('housingcreds');
Hash_Code__c data1 = Hash_Code__c.getvalues('hashcreds');
Manditory_Fields__c data2 = Manditory_Fields__c.getvalues('Hard Coded Fields');
lead CreateLead = new lead();
list<lead> newLeads = new list<lead>();
DateTime Yesterday = DateTime.now()-1;
HousingWrapper JsonRec = new HousingWrapper();
JsonRec.start_date = ''+Yesterday.getTime()/1000;
JsonRec.hash = data1.Hash__c;
JsonRec.end_date = data2.end_date__c;
JsonRec.current_time = data1.Current_time__c;
JsonRec.id = data2.Param_Id__c;
JSONGenerator gen = JSON.createGenerator(true);
gen.writestartobject();
gen.writeStringField('start_date', JsonRec.start_date);
gen.writeStringField('end_date', JsonRec.end_date);
gen.writeStringField('current_time', JsonRec.current_time);
gen.writeStringField('hash', JsonRec.hash);
gen.writeStringField('id', JsonRec.id);
gen.writeEndObject();
try{
String endPointURL = data.url__c;
String userName = data.username__c;
String password = data.password__c;
// Specify the required user name and password to access the endpoint
// As well as the header and header information
Blob headerValue = Blob.valueOf(userName + ':' + password);
String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
Httprequest request = new HttpRequest();
Http http = new Http();
request.setMethod('GET');
request.setEndpoint(endPointURL);
request.setHeader('Content-Type', 'application/json');
// Header info with remote server user name and password
request.setHeader('Authorization', authorizationHeader);
// timeout in milliseconds
//request.setTimeout(120000);
string jsonString = gen.getAsString();
system.debug('string '+jsonString);
request.setBody(jsonString);
system.debug('request' + request);
//Making call to external REST API
HttpResponse response = http.send(request);
system.debug('status code '+response.getStatusCode());
if(response.getStatusCode() == 200){
list<leadsuccessWrapper> LeadList = new list<leadsuccessWrapper>();
LeadList = (list<leadsuccessWrapper>)system.json.deserialize(response.getBody(), list<leadsuccessWrapper>.class);
System.debug('responseBody: '+response.getBody());
for(leadsuccessWrapper LeadAssign:LeadList){
CreateLead.ProjectSelectedDate__c = datetime.newInstance(LeadAssign.lead_date*1000);
CreateLead.LastName = LeadAssign.lead_name;
CreateLead.Email = LeadAssign.lead_email;
CreateLead.Phone = LeadAssign.lead_phone;
CreateLead.CountryCode = LeadAssign.country_code;
CreateLead.Project_id__c = LeadAssign.project_id;
CreateLead.Portal_Project_Name__c = LeadAssign.project_name;
CreateLead.Project_Location__c = LeadAssign.locality_name;
CreateLead.City = LeadAssign.city_name;
CreateLead.Status = data2.Enquiry_Status__c;
CreateLead.EnquirySubSource__c = data2.Enquiry_Source__c;
newLeads.add(CreateLead);
}
if(newLeads.size()!=0)
insert newLeads;
}
}catch(Exception e){
System.debug('Error::'+e.getMessage());
}
}
public class HousingWrapper {
public string Start_date;
public string end_date;
public string current_time;
public string id;
public string hash;
}
public class leadsuccessWrapper{
public integer lead_date;
public String lead_name;
public String lead_email;
public String lead_phone;
public String country_code;
public string project_id;
public String project_name;
public String locality_name;
public String city_name;
}
}
could any one suggest where i am going wrong.
here is my class:
public class housingcallout {
@future(callout=true)
public static void sendhousingCalloutREST(){
Housing_creds__c data = Housing_creds__c.getvalues('housingcreds');
Hash_Code__c data1 = Hash_Code__c.getvalues('hashcreds');
Manditory_Fields__c data2 = Manditory_Fields__c.getvalues('Hard Coded Fields');
lead CreateLead = new lead();
list<lead> newLeads = new list<lead>();
DateTime Yesterday = DateTime.now()-1;
HousingWrapper JsonRec = new HousingWrapper();
JsonRec.start_date = ''+Yesterday.getTime()/1000;
JsonRec.hash = data1.Hash__c;
JsonRec.end_date = data2.end_date__c;
JsonRec.current_time = data1.Current_time__c;
JsonRec.id = data2.Param_Id__c;
JSONGenerator gen = JSON.createGenerator(true);
gen.writestartobject();
gen.writeStringField('start_date', JsonRec.start_date);
gen.writeStringField('end_date', JsonRec.end_date);
gen.writeStringField('current_time', JsonRec.current_time);
gen.writeStringField('hash', JsonRec.hash);
gen.writeStringField('id', JsonRec.id);
gen.writeEndObject();
try{
String endPointURL = data.url__c;
String userName = data.username__c;
String password = data.password__c;
// Specify the required user name and password to access the endpoint
// As well as the header and header information
Blob headerValue = Blob.valueOf(userName + ':' + password);
String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
Httprequest request = new HttpRequest();
Http http = new Http();
request.setMethod('GET');
request.setEndpoint(endPointURL);
request.setHeader('Content-Type', 'application/json');
// Header info with remote server user name and password
request.setHeader('Authorization', authorizationHeader);
// timeout in milliseconds
//request.setTimeout(120000);
string jsonString = gen.getAsString();
system.debug('string '+jsonString);
request.setBody(jsonString);
system.debug('request' + request);
//Making call to external REST API
HttpResponse response = http.send(request);
system.debug('status code '+response.getStatusCode());
if(response.getStatusCode() == 200){
list<leadsuccessWrapper> LeadList = new list<leadsuccessWrapper>();
LeadList = (list<leadsuccessWrapper>)system.json.deserialize(response.getBody(), list<leadsuccessWrapper>.class);
System.debug('responseBody: '+response.getBody());
for(leadsuccessWrapper LeadAssign:LeadList){
CreateLead.ProjectSelectedDate__c = datetime.newInstance(LeadAssign.lead_date*1000);
CreateLead.LastName = LeadAssign.lead_name;
CreateLead.Email = LeadAssign.lead_email;
CreateLead.Phone = LeadAssign.lead_phone;
CreateLead.CountryCode = LeadAssign.country_code;
CreateLead.Project_id__c = LeadAssign.project_id;
CreateLead.Portal_Project_Name__c = LeadAssign.project_name;
CreateLead.Project_Location__c = LeadAssign.locality_name;
CreateLead.City = LeadAssign.city_name;
CreateLead.Status = data2.Enquiry_Status__c;
CreateLead.EnquirySubSource__c = data2.Enquiry_Source__c;
newLeads.add(CreateLead);
}
if(newLeads.size()!=0)
insert newLeads;
}
}catch(Exception e){
System.debug('Error::'+e.getMessage());
}
}
public class HousingWrapper {
public string Start_date;
public string end_date;
public string current_time;
public string id;
public string hash;
}
public class leadsuccessWrapper{
public integer lead_date;
public String lead_name;
public String lead_email;
public String lead_phone;
public String country_code;
public string project_id;
public String project_name;
public String locality_name;
public String city_name;
}
}