0

I tried to add the lead to exacttarget api, but always get error "Bad Request". All the code are follow the sample from Exacttarget, can anyone hlep

Below is the SOPA envelop:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Header>
     <Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <UsernameToken>
           <Username>****</Username>
           <Password>****</Password>
        </UsernameToken>
     </Security>
  </Header>
  <Body>
     <CreateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
        <Objects xsi:type="Subscriber">
           <EmailAddress>test@example</EmailAddress>
           <SubscriberKey>test@example</SubscriberKey>
           <EmailTypePreference>HTML</EmailTypePreference>
           <Attributes>
              <Name>FIRST_NAME</Name>
              <Value>test</Value>
           </Attributes>
           <Attributes>
              <Name>LAST_NAME</Name>
              <Value>test</Value>
           </Attributes>
           <Attributes>
              <Name>BIRTHDAY</Name>
              <Value>'04/03/1988'</Value>
           </Attributes>
           <lists>
                    <partnerkey xsi:nil="true"></partnerkey>
                    <id>111111</id>
                    <objectid xsi:nil="true"></objectid>
                    <status>Active</status>
            </lists>
           <Status>Active</Status>
        </Objects>
     </CreateRequest>
  </Body>
</Envelope>

Here is my curl code:

$endpoint = 'https://webservice.s6.exacttarget.com/service.asmx';
    $soap_do = curl_init();
    curl_setopt($soap_do, CURLOPT_URL, $endpoint);
    curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
    curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($soap_do, CURLOPT_POST, true);
    curl_setopt($soap_do, CURLOPT_POSTFIELDS, $dataString);
    curl_setopt($soap_do, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'Content-Length: ' . strlen($dataString),'SOAPAction: "http://exacttarget.com/wsdl/partnerAPI/Create"'));
$result = curl_exec($soap_do);

Please help

2 Answers2

0

The email address in your sample SOAP envelope doesn't appear to be valid. Not sure why you have single quote around the Birthday attribute value.

Here's a working SOAP envelope that I used to test this functionality in an Enterprise 2.0 account:

<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing">
   <s:Header>
      <a:Action s:mustUnderstand="1">Create</a:Action>
      <a:MessageID>urn:uuid:4f8fcac0-3506-4d01-b946-c197fad3517a</a:MessageID>
      <a:ReplyTo>
         <a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address>
      </a:ReplyTo>
   </s:Header>
   <s:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <CreateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
         <Options>
            <Client>
               <ID><!-- BU MID GOES HERE --></ID>
            </Client>
         </Options>
         <Objects xmlns:q1="http://exacttarget.com/wsdl/partnerAPI" xsi:type="q1:Subscriber">
            <q1:Client>
               <q1:ID><!-- BU MID GOES HERE --></q1:ID>
            </q1:Client>
            <q1:PartnerKey xsi:nil="true" />
            <q1:ObjectID xsi:nil="true" />
            <q1:EmailAddress>aspriggs@degdigital.com</q1:EmailAddress>
            <q1:Attributes>
               <q1:Name>Attribute1</q1:Name>
               <q1:Value>whee</q1:Value>
            </q1:Attributes>
            <q1:SubscriberKey>aspriggs@degdigital.com</q1:SubscriberKey>
            <q1:Status>Active</q1:Status>
            <q1:EmailTypePreference>HTML</q1:EmailTypePreference>
            <q1:Lists>
               <q1:PartnerKey xsi:nil="true" />
               <q1:ID><!-- LIST ID GOES HERE --></q1:ID>
               <q1:ObjectID xsi:nil="true" />
               <q1:Status>Active</q1:Status>
            </q1:Lists>
         </Objects>
      </CreateRequest>
   </s:Body>
</s:Envelope>

Also, there are a lot more people answering SFMC questions over at salesforce.stackexchange.com -- mostly tagged with marketing-cloud, ampscript, and soap-api.

Community
  • 1
  • 1
Adam Spriggs
  • 626
  • 8
  • 23
0

If you want to test your SOAP requests try out my nifty script:

<?php
if(isset($_POST['request'])){
    $XML = $_POST['request'];
    $URL = $_POST['url'];
    $ch = curl_init("$URL");
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch,CURLOPT_POST,1);
    curl_setopt($ch,CURLOPT_TIMEOUT, 60);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$XML);
    $result=curl_exec ($ch);
    curl_close($ch);
}
?>
<form method="post" style="margin: 0; padding: 0;">
    <input name='url' type="text" placeholder="URL here" value="<?php if(isset($_POST['url'])) echo $_POST['url']; ?>" style="height: 10%; width:90%">
    <button style="width: 9%; height: 10%;">LOAD SOAP</button>
    <div style="width: 49%; float:left;">
        <textarea style="width: 100%; height:89%;" placeholder='REQUEST HERE' name="request"><?php if(isset($_POST['request'])) echo $_POST['request']; ?></textarea>
    </div>
    <div style="width: 50%; display: inline;">
        <textarea placeholder="RESPONSE HERE" disabled="true" style="width: 50%; height: 40%;"><?php if(isset($result)) echo strtok($result, '<'); ?></textarea>
        <textarea placeholder="RESPONSE HERE" disabled="true" style="width: 50%; height: 49%;"><?php if(isset($result)) $config = array('indent'=>true,'output-xml'=>true,'input-xml'=> true); $tidyxml = new tidy; $tidyxml->parseString(strstr($result, '<'), $config, 'utf8'); echo $tidyxml;?></textarea>
    </div>
</form>
Robert Pounder
  • 1,490
  • 1
  • 14
  • 29