Iftekhar-ifti / analytics-issues

Automatically exported from code.google.com/p/analytics-issues
0 stars 0 forks source link

Management API Cost Data Upload .csv Doesn't Have Filename #791

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
---------------------------------------------------------------------------
NOTE: This tool is not designed to request help. It is only for reporting
issues and requesting features for the Google Analytics libraries.

If you are a developer and you need help, visit:
https://developers.google.com/analytics/help/

If you are not a developer and you need help, visit:
https://support.google.com/analytics
---------------------------------------------------------------------------
Name of affected component: Core Reporting API

Name of related library and version, if applicable (e.g. Java, Python,
HTTP, Objective-C, etc.):  NA

Issue summary:
Provide a brief summary of the issue you're experiencing.
Need to include filename of .csv when using Management API to import cost data 
files.

Steps to reproduce issue:
1.  Filename is blank when importing cost data .csv file via Management API
2.
3.

Expected output:
What do you expect to see after performing the above steps?
We would be able to see the descriptive filename we created with the .csv.  
This would be very helpful for troubleshooting cost data mismatches.  We 
include the date and channel (yahoo, bing, etc.) in the filename, which allows 
us to understand which file we should delete, if data is corrupted or there is 
a mismatch.

Actual results:
What do you actually see after performing the above steps?
No filename for the .csv.

Notes:
Provide any additional information which might be useful here. Feel free to
attach screenshots or sample code which demonstrates the issue being
described.

Original issue reported on code.google.com by powermya...@gmail.com on 12 Nov 2015 at 2:07

Attachments:

GoogleCodeExporter commented 8 years ago
Hi Thanks for writing in. This is an issue we are aware of and a consequence of 
the client libraries stripping the filename from POST body information. CURL 
can be used to upload a file and the filename remains in the POST body and it 
will be preserved in the UI.

Original comment by mcoh...@google.com on 16 Nov 2015 at 4:53

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hi mcoh...@google.com

I wasn't sure whether to post here or in the Groups forum 
(https://groups.google.com/forum/#!topic/google-analytics-management-api/GkA6bA0
MTPo).

This filename issue is a problem for people uploading multiple files at around 
the same time. No filename makes debugging difficult. If one of your uploads 
fails for some reason, being clear about which files have gone in successfully 
is very helpful. 

I'm working on a Python project, but your note about cURL gave me hope, and 
I've spent hours now with a bash script trying to achieve what you describe. 
I've been able successfully to cURL uploads in as media, resumable and 
multipart types but I cannot get the filename to show in the GA UI by any means.

Please can you help, by providing detail specifying the cURL parameters and 
request body that will work?

Thanks very much

Kevin

Original comment by kevin.jo...@croud.co.uk on 26 Jan 2016 at 11:01

GoogleCodeExporter commented 8 years ago

curl -X POST -F "upload=@YOURFILENAME.csv;type=application/octet-stream" 
"https://www.googleapis.com/upload/analytics/v3/management/accounts/XXXXXX/webpr
operties/UA-XXXXXX-1/customDataSources/CUSTOMDATASOURCEID/uploads?access_token=y
a29.REPLACEWIHTYOURVALIDTOKEN" -v

Original comment by mcoh...@google.com on 26 Jan 2016 at 11:08

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Thanks very much! I really wish I'd asked sooner :)

This works perfectly, and for Python you can use pycURL. This is the function 
I'm using.

import pycurl
import json

def curlUpload(accountId, webPropertyId, customDataSourceId, csv):
        credential_path = 'PATHTOYOURCREDENTIALSJSONFILE'
        f = open(credential_path)
        googleAccessToken = json.loads(f.read())['access_token']

        c = pycurl.Curl()
        c.setopt(c.URL, 'https://www.googleapis.com/upload/analytics/v3/management/accounts/' + accountId + '/webproperties/' + webPropertyId + '/customDataSources/' + customDataSourceId + '/uploads?access_token=' + googleAccessToken)
        c.setopt(c.HTTPPOST, [
        ('fileupload', (
                c.FORM_FILE, csv,
                c.FORM_CONTENTTYPE, 'application/octet-stream'
        )),
        ])
        c.perform()
        c.close()

Kevin

Original comment by kevin.jo...@croud.co.uk on 27 Jan 2016 at 6:45