[SalesForce] Marketing Cloud REST API: How to list Data Extension Attributes

Using REST API v1 and trying to find a simple way to list all attributes for a particular data extension. My main objective is to send an event to initiate a journey (API: interaction/v1/events). In order to send an event I need to populate EventDefinitionKey and contact attributes for Data.

I'm able to list event definitions (API: interaction/v1/eventDefinitions) which contains id, dataExtensionId and dataExtensionName. Awesome and easy, but I can't figure out which endpoint to hit to list attributes for data extension to populate event Data.

API /contacts/v1/attributeSetDefinitions is great but lists every data extension with attributes which feels heavy handed and unnecessary. Attribute set definitions can be filtered with /contacts/v1/schemas/{schemaId}/attributeSetDefinitions/{id} but now schema ID needs to be fetched too resulting in more API calls and seemingly unnecessary work.

Is there a convenient API endpoint to save me all this trouble? If not, what's a recommended workaround?

Best Answer

We managed to retrieve the fields of a given DE using SOAP Api, you also can place it in a REST call. You can use a token or a User/pwd to authenticate.

Example of rest call using POSTMAN:

        POST /Service.asmx HTTP/1.1 
        Host: <Your host instance ie: webservice.s6.exacttarget.com> 
        Content-Type: text/xml 
        SOAPAction: "Retrieve" 
        Cache-Control: no-cache 
        Postman-Token: 588f0a33-ff05-de0f-b4f2-28ce7751c582

        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:par="http://exacttarget.com/wsdl/partnerAPI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <!--<soapenv:Header>    
    <fueloauth xmlns="http://exacttarget.com"><YOUR TOKEN></fueloauth>   
    </soapenv:Header>-->    
    <soapenv:Header>
                  <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
                     <wsse:UsernameToken>
                        <wsse:Username><YOUR USERNAME></wsse:Username>
                        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"><YOUR PWD></wsse:Password>
                     </wsse:UsernameToken>
                  </wsse:Security>    
</soapenv:Header>    
<soapenv:Body>
                  <RetrieveRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
                     <RetrieveRequest>
                        <ObjectType>DataExtensionField</ObjectType>
                        <Properties>FieldType</Properties>
                        <Properties>Name</Properties>
                        <Properties>IsRequired</Properties>
                        <Properties>MaxLength</Properties>
                        <Properties>Ordinal</Properties>
                        <Properties>Scale</Properties>  
                        <Filter xsi:type="SimpleFilterPart">
                           <Property>DataExtension.CustomerKey</Property>
                           <SimpleOperator>equals</SimpleOperator>
                           <Value><YOUR DE_CustomerKey></Value>
                        </Filter>
                        <QueryAllAccounts>false</QueryAllAccounts>
                        <Retrieves />
                        <Options>
                           <SaveOptions />
                           <IncludeObjects>true</IncludeObjects>
                        </Options>
                     </RetrieveRequest>
                  </RetrieveRequestMsg>    
        </soapenv:Body> 
        </soapenv:Envelope>
Related Topic