1

I am trying to extract the data in one of my data extensions. The data extension currently has one field which is the client ID. I am using the SOAP api and following the guide located here:

https://developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/retrieving_data_from_a_data_extension.htm

I am writing a java application and and sending the soap envelope from there. This is what I have at the moment:

    public static void main(String[] args) throws IOException, SOAPException {
    try {
        String URL = "https://@@@@@@@@@@@.soap.marketingcloudapis.com/Service.asmx";
        java.net.URL obj = new URL(URL);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
        con.setRequestMethod("POST");
        con.setRequestProperty("Content-Type","application/soap+xml; charset=utf-8");
        String XML = "<soapenv:Envelope xmlns:soapenv=\\\"http://schemas.xmlsoap.org/soap/envelope/\\\" xmlns:xsd=\\\"http://www.w3.org/2001/XMLSchema\\\" xmlns:xsi=\\\"http://www.w3.org/2001/XMLSchema-instance\\\">\n" +
                " <soapenv:Header>\n" +
                " <wsse:Security soapenv:mustUnderstand=\\\"1\\\" xmlns:wsse=\\\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\\\">\n" +
                " <wsse:UsernameToken wsu:Id=\\\"UsernameToken-24440876\\\" xmlns:wsu=\\\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\\\">\n" +
                " <wsse:Username>@@@@@@@</wsse:Username>\n" +
                " <wsse:Password Type=\\\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\\\">@@@@@@@@@</wsse:Password>\n" +
                " </wsse:UsernameToken>\n" +
                " </wsse:Security>\n" +
                " </soapenv:Header>\n" +
                " <soapenv:Body>\n" +
                " <RetrieveRequestMsg xmlns=\\\"http://exacttarget.com/wsdl/partnerAPI\\\">\n" +
                " <RetrieveRequest>\n" +
                " <ObjectType>SMS_Unsub_Report</ObjectType>\n" +
                " <Properties>Client_id__c</Properties>\n" +
                " <Filter xsi:type=\\\"SimpleFilterPart\\\">\n" +
                " </RetrieveRequest>\n" +
                " </RetrieveRequestMsg>\n" +
                " </soapenv:Body>\n" +
                "</soapenv:Envelope>";
        con.setDoOutput(true);
        DataOutputStream wr = new DataOutputStream(con.getOutputStream());
        wr.writeBytes(XML);
        wr.flush();
        wr.close();
        String responseStatus = con.getResponseMessage();
        System.out.println(responseStatus);
        BufferedReader in = new BufferedReader(new InputStreamReader(
                con.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();
        System.out.println("response:" + response.toString());
    } catch (Exception e) {
        System.out.println("caught excepion");
        e.printStackTrace();
    }
}

I am currently getting a Bad Request along with a response code of 400 as the response. Not sure why.

I have got the wsdl from the settings and generated the java classes from it using wsimport but not sure how to use them either.

ErrorMessage:

java.io.IOException: Server returned HTTP response code: 400 for URL: https://@@@@@@@@@@@.soap.marketingcloudapis.com/Service.asmx
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1944)
at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1939)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1938)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1508)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:263)
  • Every response includes an error message along with the response code, it would be great if you'll provide him here so we can help you. – Derminal Apr 26 at 11:09
  • Edited the question to include the error message – jwhefbhjebfhjew Apr 26 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.