简体   繁体   English

努力在 Apps 脚本中修补 JSON 响应

[英]Struggling to PATCH a JSON response in Apps Script

I'm trying to patch a JSON request using Google Apps Script.我正在尝试使用 Google Apps 脚本修补 JSON 请求。 I'm trying to change the 'bidAmountMicros' object that looks like this from the documentation我正在尝试更改文档中看起来像这样的“bidAmountMicros”object

    {
  "bidStrategy": {
    "fixedBid": {
      "bidAmountMicros": 0
    }
  }
}

I'm using Apps Script and I can't for the life of me work out where I'm going wrong.我正在使用 Apps 脚本,但我终其一生都无法找出哪里出错了。 This is how I'm trying to do it-这就是我正在尝试的方式-

    function updateBid(){
  var url = 'https://displayvideo.googleapis.com/v1/advertisers/' +
    advertiserID + '/lineItems/' + lineitemID + '?updateMask=bidStrategy';
    var body = {
      'bidStrategy': 'fixedBid',
      'bidAmountMicros': '4000000'      
    }   
    var result = JSON.parse(callApi_(url, 'PATCH', body, null));
  Logger.log(result);  
}

I'm think I'm going wrong in that the bidAmountMicros is within the 'bidStrategy' rather than a seperate object itself, but how would I call it from within that object?我认为我错了,因为 bidAmountMicros 在“bidStrategy”中,而不是单独的 object 本身,但是我如何从 object 中调用它? Sorry if this is a stupid question, pretty new to this.抱歉,如果这是一个愚蠢的问题,对此很陌生。

Thanks谢谢

I removed the parts that were not defined in your code.我删除了您的代码中未定义的部分。 This is how to create the JSON:这是创建 JSON 的方法:

function updateBid(){
    var body = {
      'bidStrategy': {
        'fixedBid':{
          'bidAmountMicros': '4000000' 
        }  
      }   
    };
  Logger.log(JSON.stringify(body));  
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM