Is there a way to get number of records in a Data Extension using API? we tried to run data query get the counts data into a new DE, but how can we use API to call the query activity getting the counts data? thank you!

Thanks for your answer. Usually ,We use some program language such as C#, Node to excute the request, not send such soap message directly. When use FuelSDK-Node-SOAP to perform start action of the query activty. it will occur error. FuelSDK-Node-SOAP : http://salesforce-marketingcloud.github.io/FuelSDK-Node-SOAP/FuelSoap.html#perform

The code we excute:

const FuelSoap = require('fuel-soap');
var SOAPoptions = {
    auth: {

        clientId: '*********',
        clientId: '*********'
    soapEndpoint: 'https://webservice.exacttarget.com/Service.asmx'

var SoapClient = new FuelSoap(SOAPoptions);

var def = {
    'CustomerKey': 'RecordCounts',

SoapClient.perform('QueryDefinition', def, function (err, response) {
    if (err) {
        console.log('Exception message:'+err.Message);
        console.log('Exception code:' + err.code);
        console.log('Exception stack:' +error.stack);

    } else {

Below is the exception info :

SoapClient.perform('QueryDefinition', def, function (err, response) {

ReferenceError: SoapClient is not defined
    at Object.<anonymous> (e:\workspace\node_space\hello\node_9a2eda60b6df3.tmp:5:1)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3

Do you know how to solve this question.

  • Do you need these counts inside or outside of Marketing Cloud? Jun 7 '18 at 11:03
  • outside. we building our own hubexchange application and we want to show end user the data extesnion record number used for this application.
    – StackBruce
    Jun 7 '18 at 13:16

No need to use the official API. Since there's an AMPscript function that returns this data, you could build a simple Cloud Page in your account that returns a JSON payload with this information:


var @key, @rowCount
set @key = QueryParameter("key")
set @rowCount = iif(empty(@key), 0, DataExtensionRowCount(@key))

]%%{ "rowCount": "%%=v(@rowCount)=%%"}

Working example:



  • thank you Adam!! that looks workable. we will take a try!!1
    – StackBruce
    Jun 7 '18 at 14:12
  • Thank you so much Adam, we can get the rowcount of dataextension with the solution you provided, but it just returns text/html. do you know how can we get json format when we submit a get request ? Thanks again!
    – StackBruce
    Jun 8 '18 at 2:44
  • That's configurable when you're creating the Cloud Page. Choose a Code Resource type and then JSON. Jun 8 '18 at 12:58
  • thank you Adam! we successfully get this done with your guidance!
    – StackBruce
    Jun 9 '18 at 17:11

You can retrieve rows count using an undocumented REST endpoint:

GET https://YOUR-HOST.rest.marketingcloudapis.com/data/v1/customobjectdata/key/<DE-KEY>/rowset?$page=1&$pagesize=1
  "links": {
    "self": "/v1/customobjectdata/token/100e08a6-6e2d-4e33-9e10-0bf30fc9ebc7/rowset?$page=1",
    "next": "/v1/customobjectdata/token/100e08a6-6e2d-4e33-9e10-0bf30fc9ebc7/rowset?$page=2"
  "requestToken": "100e08a6-6e2d-4e33-9e10-0bf30fc9ebc7",
  "tokenExpireDateUtc": "2020-10-09T12:44:32.51",
  "customObjectId": "<DE-ID>",
  "customObjectKey": "<DE-KEY>",
  "pageSize": 1,
  "page": 1,
  "count": 636,
  "items": [
      "keys": {
        "email": "foo@bar.net"
      "values": {
        "client_id": "ABCDEFGHUJKLMNOPQ",
        "country": "",
        "foo": "",
        "bar": ""
  • Does this Request work using SSJS? When I try postman, it works, but not on cloudpage Dec 23 '20 at 12:01
  • @SwatiMishra I think it is better to use DataExtensionRowCount(@key) for ssjs Dec 23 '20 at 18:07

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.