Export ad report to Google sheets with GAS

45 views
Skip to first unread message

鈴木太悠

unread,
Jun 6, 2023, 6:07:11 AM6/6/23
to outbrain-...@googlegroups.com, ku...@outbrain.com, inak...@outbrain.com
Hi,

I want to export Outbrain ad reports to Google sheets with GAS. 

I ran the following GAS code, but got a 403 error. I would like to know the cause of the error and how to fix it.
If you have sample code,I would like you to share it with me.

GAS Code
function outbrainReportToGoogleSheets() {
    var MARKETER_ID = 'xxx'; // Marketer ID
    var API_KEY = 'xxx'; // API Token

    var SPREADSHEET_ID = 'xxx'; // speadsheet ID
    var SHEET_NAME = 'xxx'; // spreadsheet name

    var START_DATE = '2023-06-01'; 
    var END_DATE = '2023-06-30'; 

    var sheet = SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName(SHEET_NAME);
 
    var url = "https://api.outbrain.com/amplify/v0.1/login";
    var payload = {
        "username": 'xxx', // account user name
        "password": 'xxx' // account user password
    };
    var options = {
        "method": "post",
        "headers": {
            "Content-Type": "application/json",
            "Accept": "application/json"
        },
        "payload": JSON.stringify(payload)
    };
 
    var response = UrlFetchApp.fetch(url, options);
    var json = JSON.parse(response.getContentText());
    var OB_ACCESS_TOKEN = json.token;
   
    url = 'https://api.outbrain.com/amplify/v0.1/reports/marketers/'+MARKETER_ID+'/campaigns?from='+START_DATE+'&to='+END_DATE;
    options = {
        "method": "get",
        "headers": {
            "Content-Type": "application/json",
            "Accept": "application/json",
            "OB-TOKEN-V1": OB_ACCESS_TOKEN
        }
    };
   
    response = UrlFetchApp.fetch(url, options);
    json = JSON.parse(response.getContentText());
   
    for (var i = 0; i < json.results.length; i++) {
        var row = [
            json.results[i].date,
            json.results[i].campaign.name,
            json.results[i].impressions,
            json.results[i].clicks,
            json.results[i].conversions,
            json.results[i].spend
        ];
        sheet.appendRow(row);
    }
}

Error message
Exception: Request failed for https://api.outbrain.com returned code 403. Truncated server response: {"message":"Access denied, you don't have permission to access the specified resource"} (use muteHttpExceptions option to examine full response)


Best regards,

Taiyu
--

Shay Shabtay

unread,
Jun 8, 2023, 3:54:24 AM6/8/23
to Outbrain-AmplifyApi
Hi, are you sure you're trying to access your own resource? please provide request id so we can look into it.

Shay Shabtay

unread,
Jun 12, 2023, 3:04:08 AM6/12/23
to Outbrain-AmplifyApi
One of our response headers, as described here:
https://amplifyv01.docs.apiary.io/#introduction/troubleshooting

鈴木太悠

unread,
Jun 13, 2023, 5:54:27 PM6/13/23
to Shay Shabtay, Outbrain-AmplifyApi
I can't get the information in the response headers and get a 403 error. Is there any other way?

2023年6月12日(月) 16:04 'Shay Shabtay' via Outbrain-AmplifyApi <outbrain-...@googlegroups.com>:
The above terms reflect a potential business arrangement, are provided solely as a basis for further discussion, and are not intended to be and do not constitute a legally binding obligation. No legally binding obligations will be created, implied, or inferred until an agreement in final form is executed in writing by all parties involved.

This email and any attachments hereto may be confidential or privileged.  If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it has gone to the wrong person. Thanks.

--
You received this message because you are subscribed to the Google Groups "Outbrain-AmplifyApi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to outbrain-amplif...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/outbrain-amplifyapi/f5f17d0c-72f5-483e-8bf9-df774f7d97abn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages