Hi,
I am trying to post an addReportRequest on the the Marketing API (v7). Returns error E0152 - wrong namespace for service. Am using the sandbox - https://sandbox.marketing.ews.yahooapis/services/v7. Cannot work out whether I am using the wrong namespace for the sandbox - cannot see anything that says what it should be so am using same as live which is "http://marketing.ews.yahooapis.com/v7" or if I am setting up the SOAP request incorrectly. Any help would be very welcome.
My request looks like below:
- <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://marketing.ews.yahooapis.com/v7" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <SOAP-ENV:Header>
- <wsse:Security>
- <wsse:UsernameToken>
<wsse:Username>******</wsse:Username>
<wsse:Password>******</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
<license xmlns="http://marketing.ews.yahooapis.com/v7">******</license>
<masterAccountID xmlns="http://marketing.ews.yahooapis.com/v7">******</masterAccountID>
<accountID xmlns="http://marketing.ews.yahooapis.com/v7">******</accountID>
</SOAP-ENV:Header>
- <SOAP-ENV:Body>
- <addReportRequest xmlns="http://marketing.ews.yahooapis.com/v7">
<accountID>******</accountID>
- <reportRequest>
<dateRange>Last7Days</dateRange>
<reportName>YahooTestReport</reportName>
<reportType>KeywordSummaryByDay</reportType>
</reportRequest>
- <fileOutputFormat>
<fileOutputType>XML</fileOutputType>
<zipped>true</zipped>
</fileOutputFormat>
</addReportRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Java code is:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package src.com;
import java.io.ByteArrayOutputStream;
import javax.xml.soap.*;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class GetKeywordSummaryJAX {
private static final String uri =
"https://sandbox.marketing.ews.yahooapis.com/services/V7/";
private static final String ns = "http://marketing.ews.yahooapis.com/v7";
private static final String xsd_ns = "http://www.w3.org/2001/XMLSchema";
private static final String xsi_ns = "http://www.w3.org/2001/XMLSchema-instance";
private static final String wsse_ns = "http://schemas.xmlsoap.org/ws/2002/07/secext";
private static final String username = "******";
private static final String password = "******";
private static final String license = "******";
private static final String masterAccountID = "******";
private static final String accountID = "******";
public static void main(String[] args) throws Exception
{
try
{
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnectionFactory.createConnection();
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage request = factory.createMessage();
SOAPMessage response = null;
request.getSOAPPart().setXmlVersion("1.0");
request.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "UTF-8");
SOAPEnvelope envelope = request.getSOAPPart().getEnvelope();
SOAPHeader header = request.getSOAPHeader();
SOAPBody body = request.getSOAPBody();
header.detachNode();
createXMLNamespaces(envelope);
createRequestHeader(
envelope, request.getSOAPPart().getEnvelope().addHeader());
createGetCampaignsRequestBody(body);
request.saveChanges();
ByteArrayOutputStream boas = new ByteArrayOutputStream();
request.writeTo(boas);
System.out.println(boas.toString());
//response = connection.call(request, new URL(uri + "/CampaignService"));
//boas = new ByteArrayOutputStream();
//response.writeTo(boas);
//System.out.println(boas.toString());
request.getSOAPBody().detachNode();
body = request.getSOAPPart().getEnvelope().addBody();
createAddReportRequestBody(body);
request.saveChanges();
boas = new ByteArrayOutputStream();
request.writeTo(boas);
System.out.println(boas.toString());
response = connection.call(request, new URL(uri + "/BasicReportService"));
boas = new ByteArrayOutputStream();
response.writeTo(boas);
System.out.println(boas.toString());
connection.close();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
private static void createXMLNamespaces(SOAPEnvelope envelope) throws Exception
{
envelope.addNamespaceDeclaration("ns", ns);
envelope.addNamespaceDeclaration("wsse", wsse_ns);
envelope.addNamespaceDeclaration("xsi", xsi_ns);
envelope.addNamespaceDeclaration("xsd", xsd_ns);
}
private static void createRequestHeader(SOAPEnvelope envelope, SOAPHeader header)
throws Exception
{
SOAPHeaderElement securityE =
header.addHeaderElement(new QName(wsse_ns, "Security", "wsse"));
SOAPElement usernameTokenE =
securityE.addChildElement(new QName(wsse_ns, "UsernameToken", "wsse"));
SOAPElement usernameE =
usernameTokenE.addChildElement(new QName(wsse_ns, "Username", "wsse"));
usernameE.addTextNode(username);
SOAPElement passwordE =
usernameTokenE.addChildElement(new QName(wsse_ns, "Password", "wsse"));
passwordE.addTextNode(password);
SOAPHeaderElement licenseE =
header.addHeaderElement(new QName(ns, "license"));
licenseE.addTextNode(license);
licenseE.normalize();
SOAPHeaderElement masterAccountIDE =
header.addHeaderElement(new QName(ns, "masterAccountID"));
masterAccountIDE.addTextNode(masterAccountID);
SOAPHeaderElement accountIDE =
header.addHeaderElement(new QName(ns, "accountID"));
accountIDE.addTextNode(accountID);
}
private static void createAddReportRequestBody(SOAPBody body) throws Exception
{
SOAPBodyElement addReportRequestE =
body.addBodyElement(new QName(ns, "addReportRequest"));
SOAPElement accountIDE =
addReportRequestE.addChildElement(new QName(ns, "accountID"));
addReportRequestE.appendChild(accountIDE);
accountIDE.addTextNode(accountID);
SOAPElement reportRequestE =
addReportRequestE.addChildElement(new QName(ns, "reportRequest"));
//SOAPElement campaignIDsE =
// reportRequestE.addChildElement(new QName(ns, "campaignsIDs"));
//SOAPElement longE =
// campaignIDsE.addChildElement(new QName(ns, "long"));
//longE.addTextNode("135085001");
SOAPElement dateRangeE =
reportRequestE.addChildElement(new QName(ns, "dateRange"));
dateRangeE.addTextNode("Last7Days");
//SOAPElement endDateE =
// reportRequestE.addChildElement(new QName(ns, "endDate"));
//endDateE.addTextNode("2010-12-12T00:00:00");
SOAPElement reportNameE =
reportRequestE.addChildElement(new QName(ns, "reportName"));
reportNameE.addTextNode("YahooTestReport");
SOAPElement reportTypeE =
reportRequestE.addChildElement(new QName(ns, "reportType"));
reportTypeE.addTextNode("KeywordSummaryByDay");
//SOAPElement startDateE =
// reportRequestE.addChildElement(new QName(ns, "startDate"));
//startDateE.addTextNode("2010-12-12T00:00:00");
SOAPElement fileOutputFormatE =
addReportRequestE.addChildElement(new QName(ns, "fileOutputFormat"));
addReportRequestE.appendChild(fileOutputFormatE);
SOAPElement fileOutputTypeE =
fileOutputFormatE.addChildElement(new QName(ns, "fileOutputType"));
fileOutputTypeE.addTextNode("XML");
SOAPElement zippedE =
fileOutputFormatE.addChildElement(new QName(ns, "zipped"));
zippedE.addTextNode("true");
}
private static void createGetCampaignsRequestBody(SOAPBody body) throws Exception
{
body.addNamespaceDeclaration("ns", ns);
SOAPBodyElement getCampaignsE =
body.addBodyElement(new QName(ns, "getCampaigns"));
SOAPElement campaignIDsE =
getCampaignsE.addChildElement(new QName(ns, "campaignsIDs"));
SOAPElement longE =
campaignIDsE.addChildElement(new QName(ns, "long"));
longE.addTextNode("135085001");
}
}
Mike
