3

Using the Fuel PHP SDK I can add rows one at a time to my Data Extension. However, I cannot figure out how to add multiple rows in one call. Is it possible?

As I need to add between 5 and 5000 rows to a Data Extension, the overhead of adding each individually seems crazy, while the number of rows involved don't justify the complexity of a SFTP upload and a triggered import.

I have checked the Java, C#, Ruby & Python SDKs and none have an example of adding multiple rows; however the REST API (and structure of the SOAP payload) make me think this should be possible.

4 Answers 4

2

To add rows, CreateRequest can be used.

<CreateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
                <Objects xsi:type="DataExtensionObject">
                     <CustomerKey>TestDE</CustomerKey>
                     <Properties>
                          <Property>
                               <Name>Nickname</Name>
                               <Value>test1</Value>
                            </Property>
                        <Property>
                              <Name>Amount</Name>
                           <Value>7100</Value>
                        </Property>
                </Properties>
             </Objects>
             <Objects xsi:type="DataExtensionObject">
                     <CustomerKey>TestDE</CustomerKey>
                <Properties>
                          <Property>
                               <Name>Nickname</Name>
                               <Value>test2</Value>
                            </Property>
                        <Property>
                              <Name>Amount</Name>
                           <Value>8100</Value>
                        </Property>
                </Properties>
             </Objects>
    </CreateRequest>
1

I'm not familiar enough with the PHP SDK to tell you the correct syntax. But, I have confirmed you can make a single API call to upsert multiple rows in a data extension. The syntax of the soap envelope looks something like this.

<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>SomeDataExtensionKey</CustomerKey>
        <Properties>
            <Property><Name>keyfield</Name><Value>keyvalue1</Value></Property>
            <Property><Name>field2</Name><Value>data1</Value></Property>               
        </Properties>
        <Properties>
            <Property><Name>keyfield</Name><Value>keyvalue2</Value></Property>
            <Property><Name>field2</Name><Value>data2</Value></Property>               
        </Properties>                
        <Properties>
            <Property><Name>keyfield</Name><Value>keyvalue3</Value></Property>
            <Property><Name>field2</Name><Value>data3</Value></Property>               
        </Properties>                
    </Objects>
</UpdateRequest>

I hope this helps.

2
  • I tested this and found this is not working. Thanks
    – sf_user
    Commented Apr 16, 2017 at 6:43
  • This doesn't work. You will need to include a separate Objects node for each record you want to update in the Data Extension. Commented Jun 3, 2021 at 1:18
0

The answer is to create multiple "Objects".

SOAP Envelope (within "CreateRequest":

<Objects xsi:type="DataExtensionObject">
    <CustomerKey>MY_DE</CustomerKey>
    <Properties>
       <Property>
          <Name>hey</Name>
          <Value>hi</Value>
       </Property>
    </Properties>
 </Objects>
 <Objects xsi:type="DataExtensionObject">
    <CustomerKey>MY_DE</CustomerKey>
    <Properties>
       <Property>
          <Name>hey</Name>
          <Value>yo</Value>
       </Property>
    </Properties>
 </Objects>

SOAP PHP SDK

// Storing as an array will allow you to insert multiple rows in one call
$cr = new ExactTarget_CreateRequest();
$cr.Objects = array();
0

I highly recommend this resource: https://sfmcgeeks.com/2020/05/09/create-data-extensions-in-marketing-cloud-via-api/

I leveraged Postman to write this request.

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header>
      <fueloauth>{{accessToken}}</fueloauth>
   </soapenv:Header>
   <soapenv:Body>
      <CreateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
        <Options>
        </Options>
        <Objects xsi:type="DataExtensionObject">
          <PartnerKey xsi:nil="true" />
          <ObjectID xsi:nil="true" />
          <CustomerKey>SampleDataExtension</CustomerKey>
          <Properties>
            <Property>
              <Name>EmailAddress</Name>
              <Value>[email protected]</Value>
            </Property>
            <Property>
              <Name>FirstName</Name>
              <Value>John</Value>
            </Property>
            <Property>
              <Name>LastName</Name>
              <Value>Doe</Value>
            </Property>
            <Property>
              <Name>SubscriberKey</Name>
              <Value>0031234567890</Value>
            </Property>
          </Properties>
        </Objects>
        <Objects xsi:type="DataExtensionObject">
          <PartnerKey xsi:nil="true" />
          <ObjectID xsi:nil="true" />
          <CustomerKey>SampleDataExtension</CustomerKey>
          <Properties>
            <Property>
              <Name>EmailAddress</Name>
              <Value>[email protected]</Value>
            </Property>
            <Property>
              <Name>FirstName</Name>
              <Value>jane</Value>
            </Property>
            <Property>
              <Name>LastName</Name>
              <Value>Doe</Value>
            </Property>
            <Property>
              <Name>SubscriberKey</Name>
              <Value>0030987654321</Value>
            </Property>
          </Properties>
        </Objects>
      </CreateRequest>
   </soapenv:Body>
</soapenv:Envelope>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .