Jan
Jan

Reputation: 13

How to use the Google Analytics API v3 > analytics.management.uploads.uploadData methode in api explorer

i fill in the needed data: - accountId: 2465955 - webPropertyId: UA-2465955-20 - customDataSourceId: oI7aVdXXRJa_ZA5QNvLkVQ

Request:

POST https://www.googleapis.com/analytics/v3/management/accounts/2465955/webproperties/UA-2465955-20/customDataSources/oI7aVdXXRJa_ZA5QNvLkVQ/uploads?fields=customDataSourceId&key={YOUR_API_KEY}

i grant the user access to see and edit data in analytics. after this i get the error:

    400

- Hide headers -

cache-control:  private, max-age=0
content-encoding:  gzip
content-length:  160
content-type:  application/json; charset=UTF-8
date:  Wed, 05 Sep 2018 09:01:04 GMT
expires:  Wed, 05 Sep 2018 09:01:04 GMT
server:  GSE
vary:  Origin, X-Origin

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "badRequest",
    "message": "Upload request URL should start with https://www.googleapis.com/upload/analytics/..."
   }
  ],
  "code": 400,
  "message": "Upload request URL should start with https://www.googleapis.com/upload/analytics/..."
 }
}

i dont know how to send a propper request, hope somone can help me!

thx

Upvotes: 1

Views: 782

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117254

The Uploads: uploadData method is used to Upload data for a custom data source.

You can not use Google apis exploerer to upload files. It does not have that functionality it is only meant for testing.

You will need to code this yourself here is a nice example in java directly from the documentation

/*
 * Note: This code assumes you have an authorized Analytics service object.
 * See the Data Import 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().uploads().uploadData("123456",
      "UA-123456-1", "122333444455555", mediaContent).execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}

Upvotes: 0

Related Questions