Hide

Daily Uploads: upload

Requires authorization

Update/Overwrite data for a custom data source. See an example.

This method supports an /upload URI and accepts uploaded media with the following characteristics:

  • Maximum file size: 5MB
  • Accepted Media MIME types: application/octet-stream

In addition to the standard parameters, this method supports the parameters listed in the parameters table.

Request

HTTP request

POST https://www.googleapis.com/upload/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/customDataSources/customDataSourceId/dailyUploads/date/uploads

Parameters

Parameter name Value Description
Path parameters
accountId string Account Id associated with daily upload.
customDataSourceId string Custom data source Id to which the data being uploaded belongs.
date string Date for which data is uploaded. Date should be formatted as YYYY-MM-DD.
webPropertyId string Web property Id associated with daily upload.
Required query parameters
uploadType string The type of upload request to the /upload URI. Acceptable values are:
  • media - Simple upload. Upload the media data.
  • resumable - Resumable upload. Upload the file in a resumable fashion, using a series of at least two requests.
appendNumber integer Append number for this upload indexed from 1. Acceptable values are 1 to 20, inclusive.
type string Type of data for this upload.

Acceptable values are:
  • "cost": Value for specifying cost data upload.
Optional query parameters
reset boolean Reset/Overwrite all previous appends for this date and start over with this file as the first upload. (Default: false)

Authorization

This request requires authorization with at least one of the following scopes (read more about authentication and authorization).

Scope
https://www.googleapis.com/auth/analytics
https://www.googleapis.com/auth/analytics.edit

Request body

Do not supply a request body with this method.

Response

If successful, this method returns a response body with the following structure:

{
  "kind": "analytics#dailyUploadAppend",
  "accountId": string,
  "webPropertyId": string,
  "customDataSourceId": string,
  "date": string,
  "appendNumber": integer,
  "nextAppendLink": string
}
Property name Value Description Notes
kind string Resource type for Analytics daily upload append.
accountId string Account Id to which this daily upload append belongs.
webPropertyId string Web property Id of the form UA-XXXXX-YY to which this daily upload append belongs.
customDataSourceId string Custom data source Id to which this daily upload append belongs.
date string Date associated with daily upload append.
appendNumber integer Append number.

Examples

Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).

Java

Uses the Java client library.

/*
 * Note: This code assumes you have an authorized Analytics service object.
 * See the Daily Uploads Developer Guide for details.
 */


// This request uploads a file for the authorized user.
File file = new File("data.csv");
InputStreamContent mediaContent = new InputStreamContent("application/octet-stream",
    new FileInputStream(file));
mediaContent.setLength(file.length());
try {
  analytics.management().dailyUploads().upload("123456", "UA-123456-1",
      "7654321", "2012-10-31", 1, "cost", mediaContent).execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}

Python

Uses the Python client library.

# Note: This code assumes you have an authorized Analytics service object.
# See the Daily Upload Developer Guide for details.

# This request uploads a file data.csv to a particular customDataSource.
# Note that this example makes use of the MediaFileUpload Object from the
# apiclient.http module.
from apiclient.http import MediaFileUpload
try:
  media = MediaFileUpload('data.csv',
                          mimetype='application/octet-stream',
                          resumable=False)

  daily_upload = analytics.management().dailyUploads().upload(
      accountId='1234',
      webPropertyId='UA-1234-1',
      customDataSourceId='123456789',
      date='2012-10-31',
      appendNumber=1,
      reset=true,
      type='cost',
      media_body=media).execute()

except TypeError, error:
  # Handle errors in constructing a query.
  print 'There was an error in constructing your query : %s' % error

except HttpError, error:
  # Handle API errors.
  print ('There was an API error : %s : %s' %
         (error.resp.status, error.resp.reason))