---
updatedAt: 2026-03-01T18:52:46.000Z
agentTools:
  siteIndex: https://techdocs.akamai.com/llms.txt
  projectIndex: https://techdocs.akamai.com/datastream2/llms.txt
---

# Create a stream for New Relic (v2)

```node Node
const EdgeGrid = require("akamai-edgegrid");
const os = require("os");
const edgercPath = os.homedir + "/.edgerc.txt";
const edgercSection = "default";
const eg = new EdgeGrid({
    path: edgercPath,
    section: edgercSection
});

const url = 'https://hostname/datastream-config-api/v2/log/streams?activate=true';
const options = {
  method: 'POST',
  headers: {accept: 'application/json', 'content-type': 'application/json'},
  body: JSON.stringify({
    properties: [{propertyId: 349772}, 
                 {propertyId: 349770}],
    datasetFields: [{datasetFieldId: 1000}, 
                    {datasetFieldId: 1002}, 
                    {datasetFieldId: 1023}],
    destination: {
      destinationType: 'NEWRELIC',
      displayName: 'newrelic',
      endpoint: 'https://log-api.newrelic.com/log/v1/',
      authToken: 'SDSXXX-28ff-XXXX-JSHSJS-XXXXXX',
      contentType: 'application/json',
      customHeaderName: 'X-Request-Header',
      customHeaderValue: 'Header-Value'
    },
     deliveryConfiguration: {
      frequency: {
        intervalInSeconds: 30,
      },
      format: "JSON"
    },   
    notificationEmails: ['useremail1@domain.com', 'useremail2@domain.com'],
    collectMidgress: true,
    streamName: 'DD Stream',
    groupId: 21484,
    contractId: '2-FGHIJ'
  })
  
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error('error:' + err));
```

```shell cURL
activate=true

egcurl --eg-section default --request POST \
  --url "https://hostname/datastream-config-api/v2/log/streams?activate=$activate" \
  --header "Accept: application/json" \
  --header "Content-Type: application/json" \
  --data '
  
  {
     "properties": [
          {
               "propertyId": 349772
          },
          {
               "propertyId": 349770
          }
     ],
     "datasetFields": [
          {
               "datasetFieldId": 1000
          },
          {
               "datasetFieldId": 1002
          },
          {
               "datasetFieldId": 1023
          }
     ],
			"destination": {
          "destinationType": "NEWRELIC",
          "displayName": "newrelic",
          "endpoint": "https://log-api.newrelic.com/log/v1/",
          "authToken": "SDSXXX-28ff-XXXX-JSHSJS-XXXXXX",
          "contentType": "application/json",
          "customHeaderName": "X-Request-Header",
          "customHeaderValue": "Header-Value"
     },
     "deliveryConfiguration": {
          "frequency": {
               "intervalInSeconds": 30
          },
     			"format": "JSON",
     "notificationEmails": [
          "useremail1@domain.com",
          "useremail2@domain.com"
     ],
     "collectMidgress": true,
     "streamName": "DD Stream",
     "groupId": 21484,
     "contractId": "2-FGHIJ"
}
'
```

```python Python
import requests
import json
from akamai.edgegrid import EdgeGridAuth, EdgeRc
from urllib.parse import urljoin

edgerc = EdgeRc('~/.edgerc.txt')
section = 'default'
baseurl = 'https://%s' % edgerc.get(section, 'host')

session = requests.Session()
session.auth = EdgeGridAuth.from_edgerc(edgerc, section)
 

path = '/datastream-config-api/v2/log/streams'
headers = {
  "Content-Type": "application/json",

  "Accept": "application/json"}
payload = {
    "streamName": "DD Stream",
    "groupId": 21484,
    "contractId": "2-FGHIJ",
    "notificationEmails": [
        "useremail1@domain.com",
        "useremail2@domain.com"
    ],
    "properties": [
        {
            "propertyId": 349772
        },
        {
            "propertyId": 349770
        }
    ],
    "datasetFields": [
        {
            "datasetFieldId": 1000
        },
        {
            "datasetFieldId": 1002
        },
        {
            "datasetFieldId": 1023
        }
    ],
    "deliveryConfiguration": {
        "frequency": {
            "intervalInSeconds": 30
        },
        "format": "JSON"
    },
    destination: {
      destinationType: 'NEWRELIC',
      displayName: 'newrelic',
      endpoint: 'https://log-api.newrelic.com/log/v1/',
      authToken: 'SDSXXX-28ff-XXXX-JSHSJS-XXXXXX',
      contentType: 'application/json',
      customHeaderName: 'X-Request-Header',
      customHeaderValue: 'Header-Value'
    },
    "collectMidgress": true
} 
querystring = {
  "activate": true
}  

result = session.get(urljoin(baseurl, path), headers=headers, json=payload, querystring=querystring)
print(result.status_code)
print(json.dumps(result.json(), indent=2)) 
```

```json Response Example
{
  "streamName": "DD Stream",
  "streamId": 7050,
  "streamVersion": 1,
  "groupId": 21484,
  "contractId": "2-FGHIJ",
  "properties": [
    {
      "propertyId": 349772,
      "propertyName": "example.com"
    },
    {
      "propertyId": 349770,
      "propertyName": "example.akamai.com"
    }
  ],
  "datasetFields": [
    {
      "datasetFieldId": 1000,
      "datasetFieldName": "CP code",
      "datasetFieldJsonKey": "cp"
    },
    {
      "datasetFieldId": 1002,
      "datasetFieldName": "Request ID",
      "datasetFieldJsonKey": "reqId"
    },
    {
      "datasetFieldId": 1023,
      "datasetFieldName": "Cookie",
      "datasetFieldJsonKey": "cookie"
    }
  ],
		"destination": {
       "destinationType": "GCS",
       "displayName": "GCSDestination",
       "bucket": "datastream",
       "projectId": "ds2-connect",
       "path": "log/edgelogs/{%Y/%m/%d}",
  },
  "deliveryConfiguration": {
    "fieldDelimiter": "SPACE",
    "frequency": {
      "intervalInSeconds": 30
    },
    "format": "STRUCTURED"
  },
  "latestVersion": 1,
  "productId": "Dynamic_Site_Accelerator",
  "streamStatus": "ACTIVATING",
  "createdBy": "johndoe",
  "createdDate": "2022-02-05T13:31:30Z",
  "modifiedBy": "johndoe",
  "modifiedDate": "2022-02-05T13:31:30Z",
  "notificationEmails": [
    "useremail1@domain.com",
    "useremail2@domain.com"
  ],
  "collectMidgress": true
}
```

# Set up authorization

<!-- node@1-8 -->
<!-- shell@3-6 -->
<!-- python@1-11 -->

Before you can this API, you need to [Create authentication credentials](https://techdocs.akamai.com/developer/docs/set-up-authentication-credentials).

Then, you can use these code samples to apply the token values to your requests.

# Name the stream

<!-- node@37 -->
<!-- shell@48 -->
<!-- python@20 -->

In the `streamName` field, enter a meaningful, human-readable name for your stream. It's useful for identification purposes.

# Fetch group and contract information

<!-- node@38-39 -->
<!-- shell@49-50 -->
<!-- python@21-22 -->

Run the [List groups](https://techdocs.akamai.com/datastream2/reference/get-groups) operation to get and store these values:

- the `groupId` of the group the product you want to monitor belongs to.

- `contractId` of the contract that belongs to the selected group.

# Set e-mail notifications

<!-- node@35 -->
<!-- shell@43-45 -->
<!-- python@23-25 -->

You can optionally enter a comma-delimited list of e-mail addresses to get notifications about events related to the stream (such as activating and deactivating it). 

If you omit this member, DataStream will not send e-mail notifications.

# Choose the properties

<!-- node@15-16 -->
<!-- shell@9-16 -->
<!-- python@27-33 -->

Fetch properties available for the group you previously selected. To do that, use the stored `groupId` in the [List properties by group](https://techdocs.akamai.com/datastream2/reference/get-group-properties) operation and store the `propertyId` values that you want to monitor in this stream. 

Enter them in the `properties` array of the request body.

# Choose the data set fields

<!-- node@17-19 -->
<!-- shell@18-27 -->
<!-- python@35-44 -->

Run the [List data set fields](https://techdocs.akamai.com/datastream2/reference/get-dataset-fields) operation and pick the `datasetFieldId` values of the fields that you want to monitor in your logs.

Values for these fields will appear in the log lines in the order you list them in the `datasetFields` array.

# Build the delivery configuration object

<!-- node@29-33 -->
<!-- shell@38-46 -->
<!-- python@46-50 -->

Build a `deliveryConfiguration` object where you specify how the logs are delivered.

# Set the log bundling frequency

<!-- node@30-31 -->
<!-- shell@39-40 -->
<!-- python@47-48 -->

In the `frequency` object, set the `intervalInSeconds` to `30` or `60` seconds to specify the time after which the API bundles your logs into a file and sends to a destination.

# Set the log format

<!-- node@33 -->
<!-- shell@42-43 -->
<!-- python@50 -->

Set the `format` that you want to receive your logs in. For new Relic, you can choose only `JSON`.

# Configure the destination

<!-- node@20-28 -->
<!-- shell@29-37 -->
<!-- python@52-59 -->

Use the `destination` array to configure destination details, such as the upload path and authentication credentials.

# Enter the destination type

<!-- node@21 -->
<!-- shell@30 -->
<!-- python@53 -->

In `destinationType`, enter `NEWRELIC`, the identifier for the New Relic destination in DataStream 2.

# Name the destination

<!-- node@22 -->
<!-- shell@31 -->
<!-- python@54 -->

Enter a meaningful `displayName` to identify the destination.

# Set the New Relic endpoint

<!-- node@23 -->
<!-- shell@32 -->
<!-- python@55 -->

Enter a New Relic endpoint URL in the `https://<newrelic.com>/log/v1/ `format. 

See [Introduction to the Log API](https://docs.newrelic.com/docs/logs/log-api/introduction-log-api/) in the New Relic documentation, if you want to retrieve your endpoint URL.

# Enter the New Relic token

<!-- node@24 -->
<!-- shell@33 -->
<!-- python@56 -->

Use this field to enter the Log API token you created for your account in New Relic.

# Configure custom headers

<!-- node@25-27 -->
<!-- shell@35-36 -->
<!-- python@57-59 -->

You can optionally choose the content type passed in the log file, and enter the name and value for the header accepted by your New Relic endpoint.

# Set the content type

<!-- node@25 -->
<!-- shell@34 -->
<!-- python@57 -->

Enter the type of the resource passed in the request's custom header. For details, see the additional options in [Stream logs to a New Relic endpoint](https://techdocs.akamai.com/datastream2/docs/stream-new-relic#additional-options).

# Enter the custom header details

<!-- node@26-27 -->
<!-- shell@35-36 -->
<!-- python@58-59 -->

Use this field to enter a human-readable (only alphanumeric, dash, and underscore characters) name for the request's custom header. Then, enter the custom header's contents passed with the request that contains information about the client connection.

# Enable logging midgress traffic

<!-- node@36 -->
<!-- shell@47 -->
<!-- python@61 -->

Set `collectMidgress` to `true` if you want to to get data on traffic rom within the Akamai platform, such as between two edge servers.

# Activate the stream

<!-- node@10 -->
<!-- shell@1 -->
<!-- python@63-64 -->

Optionally, set the `activate` field to `true` to start activating the stream on request. The stream activates in around 60 minutes after making the request.

# Call the API



Run POST on the request URL with the request body object.

# Store the response values



The response's object returns the `streamId` and `streamVersion` values for the stream version you created.

You can use these values for other operations, such as [Get a stream](https://techdocs.akamai.com/datastream2/reference/get-stream) to list stream details.