You need to sign in to do that
Don't have an account?
Soap Env DeleteRequest From Service Cloud to Marketing Cloud
I am using Apex (in Service Cloud) to call Marketing Cloud Data Extension to delete some record by email address. Below is my code. For some reason, I am getting System.HttpResponse[Status=Bad Request, StatusCode=400] error. I could not tell what is wrong with my request.. I also tried using SoapUI to test my call and I get bad request error there as well. Below is my method. Guidance appreciated.
public void SoapEnvCall()
{
String soapTemplate =
'<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">'+
' <Header>'+
'<Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">'+
'<UsernameToken>'+
'<Username>my marketing cloud username</Username>'+
' <Password>my marketing cloud password</Password>'+
' </UsernameToken>'+
' </Security>'+
' </Header>'+
' <Body>'+
' <DeleteRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">'+
' <Options/>'+
' <Objects xsi:type="DataExtensionObject">'+
' <PartnerKey xsi:nil="true"/>'+
' <ObjectID xsi:nil="true"/>'+
' <CustomerKey>my dataextension external key</CustomerKey>'+
' <Keys>'+
' <Key>'+
' <Name>Email_Address</Name>'+
' <Value>bobTest@intouchsol.com</Value>'+
' </Key>'+
' </Keys>'+
' </Objects>'+
' </DeleteRequest>'+
' </Body>'+
' </Envelope>';
System.debug('#######################soapTemplate: '+ soapTemplate);
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setHeader('SOAPAction','Delete');
req.setHeader('Accept-Encoding','gzip,deflate');
req.setHeader('Content-Type','text/xml;charset=UTF-8');
req.setHeader('User-Agent','Jakarta Commons-HttpClient/3.1');
req.setBody(soapTemplate);
req.setEndpoint('https://webservice.s7.exacttarget.com/Service.asmx');
string bodyRes = '';
try {
HttpResponse res = h.send(req);
bodyRes = res.getBody();
}
catch(System.CalloutException e) {
System.debug('Callout error: '+ e);
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL, e.getMessage()));
}
System.debug('Soapponse:' + bodyRes);
}
public void SoapEnvCall()
{
String soapTemplate =
'<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">'+
' <Header>'+
'<Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">'+
'<UsernameToken>'+
'<Username>my marketing cloud username</Username>'+
' <Password>my marketing cloud password</Password>'+
' </UsernameToken>'+
' </Security>'+
' </Header>'+
' <Body>'+
' <DeleteRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">'+
' <Options/>'+
' <Objects xsi:type="DataExtensionObject">'+
' <PartnerKey xsi:nil="true"/>'+
' <ObjectID xsi:nil="true"/>'+
' <CustomerKey>my dataextension external key</CustomerKey>'+
' <Keys>'+
' <Key>'+
' <Name>Email_Address</Name>'+
' <Value>bobTest@intouchsol.com</Value>'+
' </Key>'+
' </Keys>'+
' </Objects>'+
' </DeleteRequest>'+
' </Body>'+
' </Envelope>';
System.debug('#######################soapTemplate: '+ soapTemplate);
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setHeader('SOAPAction','Delete');
req.setHeader('Accept-Encoding','gzip,deflate');
req.setHeader('Content-Type','text/xml;charset=UTF-8');
req.setHeader('User-Agent','Jakarta Commons-HttpClient/3.1');
req.setBody(soapTemplate);
req.setEndpoint('https://webservice.s7.exacttarget.com/Service.asmx');
string bodyRes = '';
try {
HttpResponse res = h.send(req);
bodyRes = res.getBody();
}
catch(System.CalloutException e) {
System.debug('Callout error: '+ e);
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL, e.getMessage()));
}
System.debug('Soapponse:' + bodyRes);
}