1

I am unable to upsert data extension.

I have followed the adding data to data extension object example and request returns error of Violation of PRIMARY KEY constraint ... Cannot insert duplicate key in object.

Data extension has account_id set to primary key.

Following is sample of CREATE request.

<soap:Body>
  <CreateRequest 
    xmlns="http://exacttarget.com/wsdl/partnerAPI">
    <Options>
      <SaveOptions/>
    </Options>
    <Objects xsi:type="DataExtensionObject">
      <PartnerKey xsi:nil="true"/>
      <ObjectID xsi:nil="true"></ObjectID>
      <CustomerKey>Definition_Key</CustomerKey>
      <Properties>
        <Property>
          <Name>name</Name>
          <Value>Sam Sample</Value>
        </Property>
        <Property>
          <Name>email</Name>
          <Value>sample@example.com</Value>
        </Property>
        <Property>
          <Name>account_id</Name>
          <Value>12345678</Value>
        </Property>
        <Property>
          <Name>PrimaryKey</Name>
          <Value>account_id</Value>
        </Property>
      </Properties>
    </Objects>
  </CreateRequest>
</soap:Body>

1 Answer 1

1

You need to add a SaveAction of UpdateAdd in your CreateRequest UpdateRequest SaveOptions.

EDIT: (removed bad example)

EDIT: Here's one I captured from a successful operation:

<?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" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
   <s:Header>
      <a:Action s:mustUnderstand="1">Update</a:Action>
      <a:MessageID>urn:uuid:7399de64-edd5-4b99-bd43-ef7373c0fd16</a:MessageID>
      <a:ReplyTo>
         <a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address>
      </a:ReplyTo>
      <a:To s:mustUnderstand="1">https://webservice.exacttarget.com/Service.asmx</a:To>
      <o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
         <u:Timestamp u:Id="_0">
            <u:Created>2015-05-08T13:02:09.665Z</u:Created>
            <u:Expires>2015-05-08T13:07:09.665Z</u:Expires>
         </u:Timestamp>
         <o:UsernameToken u:Id="uuid-152faf22-08bb-49c1-a90c-97ef9a2cf763-1">
            <o:Username>
               <!-- Removed-->
            </o:Username>
            <o:Password>
               <!-- Removed-->
            </o:Password>
         </o:UsernameToken>
      </o:Security>
   </s:Header>
   <s:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <UpdateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
         <Options>
            <SaveOptions>
               <SaveOption>
                  <PropertyName>*</PropertyName>
                  <SaveAction>UpdateAdd</SaveAction>
               </SaveOption>
            </SaveOptions>
         </Options>
         <Objects xsi:type="DataExtensionObject">
            <PartnerKey xsi:nil="true" />
            <ObjectID xsi:nil="true" />
            <CustomerKey>DATA_EXTENSION_CUSTOMER_KEY</CustomerKey>
            <Properties>
               <Property>
                  <Name>email</Name>
                  <Value>aspriggs@degdigital.com</Value>
               </Property>
               <Property>
                  <Name>firstname</Name>
                  <Value>Adam</Value>
               </Property>
               <Property>
                  <Name>zipcode</Name>
                  <Value>55555</Value>
               </Property>
            </Properties>
         </Objects>
      </UpdateRequest>
   </s:Body>
</s:Envelope>
4
  • Can you suggest how to resolve. Response after adding UpdateAdd <CreateResponse xmlns="exacttarget.com/wsdl/partnerAPI"> <Results xsi:type="DataExtensionCreateResult"> <StatusCode>Error</StatusCode> <StatusMessage>SaveAction: UpdateAdd violation</StatusMessage> <OrdinalID>0</OrdinalID> <ErrorCode>68001</ErrorCode> <NewID>0</NewID> <ErrorMessage>SaveAction: UpdateAdd violation</ErrorMessage> </Results> <RequestID>123</RequestID> <OverallStatus>Error</OverallStatus> </CreateResponse> May 8, 2015 at 0:55
  • what are the names and data types of your target data extension? May 8, 2015 at 11:25
  • I have updated my answer. May 8, 2015 at 13:08
  • I changed request to Update and works as expected - thanks for your help. May 11, 2015 at 2:45

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.