更新广告组预算
您可以使用本接口更新广告组的总预算或设置广告组日预算或动态日预算的预定预算更改。
预定预算更改将在广告账户时区的第二天凌晨 00:00 左右生效。请注意,在广告账户时区的预算锁定期间(23:55 - 00:00),您无法修改或设置预定预算更改。
请查看币种,了解推广预算限制。
v1.2与v1.3版本对比
以下表格概括了 v1.2与v1.3接口的变化。
``xtable
|变化内容{30%}|v1.2{35%}|v1.3{35%}|
|---|---|---|
|接口路径|/v1.2/adgroup/update/budget/|/v1.3/adgroup/budget/update/|
|请求参数类型|advertiser_id: number <br>adgroup_id: number|advertiser_id: string <br>adgroup_id`: string |
## 请求
**地址** <https://business-api.tiktok.com/open_api/v1.3/adgroup/budget/update/>
**方法** POST
**Header**
```xtable
|字段|类型|描述|
|---|---|---|
|Access-Token {必填}|string|授权访问令牌。可以通过[获取访问令牌](https://ads.tiktok.com/marketing_api/docs?id=1738373164380162)接口获取。 |
|Content-Type {必填}|string|请求消息类型<br>允许值: `"application/json"` 。 |
参数
|字段{35%}|类型{15%}|描述{50%}|
|---|---|---|
|advertiser_id {必填}|string|广告主 ID。|
|budget{+条件必填} |object[]| 需至少传入 `budget` 和 `scheduled_budget` 其中之一。<ul><li>若想更新广告组的总预算,需传入 `budget`。</li><li>若想更新广告组的日预算或动态日预算,需传入 `scheduled_budget`。</li></ul><br>想要为广告组更新的总预算的有关信息。<br><br>最大数量:20。<br><br><p><span style="color:darkred"><b>注意</b></span>:广告组的总预算更新即时生效。|
#|adgroup_id{+条件必填} |string|传入对象数组 `budget` 时,本字段必填。<br><br>广告组 ID。 |
#|budget{+条件必填}|float| 传入对象数组 `budget` 时,本字段必填。<br><br>想要为广告组(`adgroup_id`)更新的总预算。 |
|scheduled_budget {+条件必填}|object[]| 需至少传入 `budget` 和 `scheduled_budget` 其中之一。<ul><li>若想更新广告组的总预算,需传入 `budget`。</li><li>若想更新广告组的日预算或动态日预算,需传入 `scheduled_budget`。</li></ul><br>想要为广告组日预算或动态日预算设置的预定预算更改(定时预算)的有关信息。<br><br>最大数量:20。<br><br><p><span style="color:darkred"><b>注意</b></span>:广告组的预定预算更改将在广告账户时区第二天凌晨 00:00 左右生效。|
#|adgroup_id{+条件必填}|string| 传入对象数组 `scheduled_budget` 时,本字段必填。<br><br>广告组 ID。 |
#|scheduled_budget{+条件必填} |float| 传入对象数组 `scheduled_budget` 时,本字段必填。<br><br>想要为广告组(`adgroup_id`)更新的日预算或动态日预算。 |
示例
(code Java java)
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import okhttp3.*;
import org.apache.http.client.utils.URIBuilder;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class Demo {
private static final String ACCESS_TOKEN = "xxx";
private static final String PATH = "/open_api/v1.3/adgroup/budget/update/";
private static final ObjectMapper mapper = new ObjectMapper();
/**
* Build request URL
*
* @param path Request path
* @return Request URL
*/
private static String buildUrl(String path) throws URISyntaxException {
URI uri = new URI("https", "business-api.tiktok.com", path, "", "");
return uri.toString();
}
/**
* Send POST request
*
* @param jsonStr Args in JSON format
* @return Response in JSON format
*/
private static String post(String jsonStr) throws IOException, URISyntaxException {
OkHttpClient client = new OkHttpClient().newBuilder().build();
String url = buildUrl(PATH);
RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonStr);
Request request = new Request.Builder()
.url(url)
.method("POST", body)
.addHeader("Content-Type", "application/json")
.addHeader("Access-Token", ACCESS_TOKEN)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
public static void main(String[] args) throws IOException, URISyntaxException {
Long advertiser_id = ADVERTISER_ID;
Double budget = BUDGET;
Long adgroup_id = ADGROUP_ID;
Long adgroup_id = ADGROUP_ID;
Double scheduled_budget = SCHEDULED_BUDGET;
// Args in JSON format
String myArgs = String.format("{\"advertiser_id\": \"%s\", \"budget\": [{\"budget\": \"%s\", \"adgroup_id\": \"%s\"}], \"scheduled_budget\": [{\"adgroup_id\": \"%s\", \"scheduled_budget\": \"%s\"}]}",advertiser_id, budget, adgroup_id, adgroup_id, scheduled_budget);
System.out.println(post(myArgs));
}
}
(/code)
(code Python python)
# coding=utf-8
import json
import requests
from six import string_types
from six.moves.urllib.parse import urlencode, urlunparse # noqa
ACCESS_TOKEN = "xxx"
PATH = "/open_api/v1.3/adgroup/budget/update/"
def build_url(path, query=""):
# type: (str, str) -> str
"""
Build request URL
:param path: Request path
:param query: Querystring
:return: Request URL
"""
scheme, netloc = "https", "business-api.tiktok.com"
return urlunparse((scheme, netloc, path, "", query, ""))
def post(json_str):
# type: (str) -> dict
"""
Send POST request
:param json_str: Args in JSON format
:return: Response in JSON format
"""
url = build_url(PATH)
args = json.loads(json_str)
headers = {
"Access-Token": ACCESS_TOKEN,
"Content-Type": "application/json",
}
rsp = requests.post(url, headers=headers, json=args)
return rsp.json()
if __name__ == '__main__':
advertiser_id = ADVERTISER_ID
budget = BUDGET
adgroup_id = ADGROUP_ID
adgroup_id = ADGROUP_ID
scheduled_budget = SCHEDULED_BUDGET
# Args in JSON format
my_args = "{\"advertiser_id\": \"%s\", \"budget\": [{\"budget\": \"%s\", \"adgroup_id\": \"%s\"}], \"scheduled_budget\": [{\"adgroup_id\": \"%s\", \"scheduled_budget\": \"%s\"}]}" % (advertiser_id, budget, adgroup_id, adgroup_id, scheduled_budget)
print(post(my_args))
(/code)
(code PHP php)
$ACCESS_TOKEN = "xxx";
$PATH = "/open_api/v1.3/adgroup/budget/update/";
/**
* Build request URL
* @param $path : Request path
* @return string
*/
function build_url($path)
{
return "https://business-api.tiktok.com" . $path;
}
/**
* Send POST request
* @param $json_str : Args in JSON format
* @return bool|string : Response in JSON format
*/
function post($json_str)
{
global $ACCESS_TOKEN, $PATH;
$curl = curl_init();
$url = build_url($PATH);
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $json_str,
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Access-Token: " . $ACCESS_TOKEN,
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
$advertiser_id = ADVERTISER_ID;
$budget = BUDGET;
$adgroup_id = ADGROUP_ID;
$adgroup_id = ADGROUP_ID;
$scheduled_budget = SCHEDULED_BUDGET;
/* Args in JSON format */
$my_args = sprintf("{\"advertiser_id\": \"%s\", \"budget\": [{\"budget\": \"%s\", \"adgroup_id\": \"%s\"}], \"scheduled_budget\": [{\"adgroup_id\": \"%s\", \"scheduled_budget\": \"%s\"}]}", $advertiser_id, $budget, $adgroup_id, $adgroup_id, $scheduled_budget);
echo post($my_args);
(/code)
(code curl http)
curl -H "Access-Token:xxx" -H "Content-Type:application/json" -X POST \
-d '{
"advertiser_id": "ADVERTISER_ID",
"budget": [
{
"budget": "BUDGET",
"adgroup_id": "ADGROUP_ID"
}
],
"scheduled_budget": [
{
"adgroup_id": "ADGROUP_ID",
"scheduled_budget": "SCHEDULED_BUDGET"
}
]
}' \
https://business-api.tiktok.com/open_api/v1.3/adgroup/budget/update/
(/code)
返回
|字段|类型|描述|
|---|---|---|
|code |number|返回码,详见[附录-返回码](https://ads.tiktok.com/marketing_api/docs?id=1737172488964097)。 |
|message |string|返回信息,详见[附录-返回码](https://ads.tiktok.com/marketing_api/docs?id=1737172488964097)。|
|data |object|返回数据 |
|request_id |string|请求的日志ID,唯一标识一个请求。|
示例
(code Success-Response http)
HTTPS/1.1 200 OK
{
"message": "OK",
"code": 0,
"data": {},
"request_id": "2020031110223101018904922300361F64"
}
(/code);