Here you go! You still need to create an endpoint that will take the posted label mappings, I hope it helps!
//Set "apiUrlAndKey" to url of API enpoint that accepts post of json data with mappings
var apiUrlAndKey = '__API_URL__';
function main() {
var labelUpdates = [];
//Push all label names to array
var labelNames = getAllLabels();
//Iterate through all labels
labelNames.forEach(function (labelName) {
//Iterate through all campaigns with that label
var campaignIterator = AdWordsApp.campaigns()
.withCondition('LabelNames CONTAINS_ANY ["' + labelName + '"]')
.get();
while (campaignIterator.hasNext()) {
var campaign = campaignIterator.next();
//Push update to object array
labelUpdates.push({label: labelName, campaignId: campaign.getId()});
}
});
var req = JSON.stringify(labelUpdates);
//Call api with mappings
//You can add authorization header to authenticate or send internal api key in query string
var options = {
method: 'POST',
payload: req,
contentType: 'application/json'
};
Logger.log('Sending request to API: ' + req);
var resp = UrlFetchApp.fetch(apiUrlAndKey, options).getContentText();
Logger.log('Response from API: ' + resp);
}
function getAllLabels() {
var labelNames = [];
var labelIterator = AdWordsApp.labels().get();
while (labelIterator.hasNext()) {
var label = labelIterator.next();
labelNames.push(label.getName());
}
return labelNames;