> ## Documentation Index
> Fetch the complete documentation index at: https://www.ayrshare.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Chiến dịch

> Lấy các Chiến dịch Quảng cáo Instagram

export const PlansAvailable = ({plans = [], maxPackRequired}) => {
  let displayPlans = plans;
  if (plans && plans.length === 1) {
    const lowerCasePlan = plans[0].toLowerCase();
    if (lowerCasePlan === "business") {
      displayPlans = ["Launch", "Business", "Enterprise"];
    } else if (lowerCasePlan === "premium") {
      displayPlans = ["Premium", "Launch", "Business", "Enterprise"];
    }
  }
  return <Note>
Available on {displayPlans.length === 1 ? "the " : ""}
{displayPlans.join(", ").replace(/\b\w/g, l => l.toUpperCase())}{" "}
{displayPlans.length > 1 ? "plans" : "plan"}.

{maxPackRequired && <span onClick={() => window.open('https://www.ayrshare.com/docs/additional/maxpack', '_self')} className="flex items-center mt-2 cursor-pointer">
 <span className="px-1.5 py-0.5 rounded text-sm" style={{
    backgroundColor: '#C264B6',
    color: 'white',
    fontSize: '12px'
  }}>
   Max Pack required
 </span>
</span>}
</Note>;
};

export const HeaderAPI = ({noProfileKey, profileKeyRequired}) => <>
    <ParamField header="Authorization" type="string" required>
      <a href="/docs/apis/overview#authorization">API Key</a> of the Primary Profile.
      <br />
      <br />
      Format: <code>Authorization: Bearer API_KEY</code>
    </ParamField>
    {!noProfileKey && (profileKeyRequired ? <ParamField header="Profile-Key" type="string" required>
          <a href="/docs/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField> : <ParamField header="Profile-Key" type="string">
          <a href="/docs/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField>)}
  </>;

<PlansAvailable plans={["premium"]} maxPackRequired={false} />

Lấy các chiến dịch quảng cáo cho một tài khoản quảng cáo Instagram cụ thể. Endpoint này cung cấp thông tin chi tiết về các chiến dịch, bao gồm ngân sách, trạng thái, chỉ số hiệu suất và thông tin lịch trình.

<ul className="custom-bullets">
  <li>
    Trạng thái chiến dịch có thể là một trong: "ACTIVE", "PAUSED", "DELETED", "ARCHIVED", "IN\_PROCESS", hoặc
    "WITH\_ISSUES"
  </li>

  <li>Đối tượng `metrics` chứa dữ liệu hiệu suất cho chiến dịch</li>
  <li>Trường `budgetRemaining` biểu thị ngân sách còn lại theo đơn vị tiền tệ của tài khoản</li>
  <li>Kết quả được cache trong 10 phút để tối ưu hóa hiệu suất</li>
</ul>

## Tham số Header

<HeaderAPI />

## Tham số Query

<ParamField query="accountId" type="string" required>
  ID của tài khoản quảng cáo để lấy các chiến dịch.

  ID tài khoản quảng cáo, có hoặc không có tiền tố `act_` (`1234567890` hoặc `act_1234567890`).
</ParamField>

<ParamField query="limit" type="number" default={100}>
  Giới hạn số lượng chiến dịch được trả về.
</ParamField>

<RequestExample>
  ```bash cURL theme={"system"}
  curl \
  -H "Authorization: Bearer API_KEY" \
  -X GET https://api.ayrshare.com/api/ads/instagram/campaigns?accountId=1234567890
  ```

  ```javascript JavaScript theme={"system"}
  const API_KEY = "API_KEY";

  fetch("https://api.ayrshare.com/api/ads/instagram/campaigns?accountId=1234567890", {
        method: "GET",
        headers: {
          "Authorization": `Bearer ${API_KEY}`
        }
      })
        .then((res) => res.json())
        .then((json) => console.log(json))
        .catch(console.error);
  ```

  ```python Python theme={"system"}
  import requests

  headers = {'Authorization': 'Bearer API_KEY'}

  r = requests.get('https://api.ayrshare.com/api/ads/instagram/campaigns?accountId=1234567890', headers=headers)

  print(r.json())
  ```

  ```php PHP theme={"system"}
  <?php
  $apiKey = "API_KEY";
  $url = "https://api.ayrshare.com/api/ads/instagram/campaigns?accountId=1234567890";

  $options = [
      'http' => [
          'header' => "Authorization: Bearer " . $apiKey,
          'method' => 'GET'
      ]
  ];

  $context = stream_context_create($options);
  $response = file_get_contents($url, false, $context);

  $result = json_decode($response, true);
  print_r($result);
  ?>
  ```

  ```csharp C# theme={"system"}
  using System;
  using System.Net.Http;
  using System.Threading.Tasks;

  class Program
  {
      static async Task Main()
      {
          string apiKey = "API_KEY";
          string url = "https://api.ayrshare.com/api/ads/instagram/campaigns?accountId=1234567890";

          using (HttpClient client = new HttpClient())
          {
              client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");

              HttpResponseMessage response = await client.GetAsync(url);
              string content = await response.Content.ReadAsStringAsync();

              Console.WriteLine(content);
          }
      }
  }
  ```

  ```go Go theme={"system"}
  package main

  import (
      "fmt"
      "io/ioutil"
      "net/http"
  )

  func main() {
      apiKey := "API_KEY"
      url := "https://api.ayrshare.com/api/ads/instagram/campaigns?accountId=1234567890"

      req, _ := http.NewRequest("GET", url, nil)
      req.Header.Add("Authorization", "Bearer " + apiKey)

      client := &http.Client{}
      resp, err := client.Do(req)
      if err != nil {
          fmt.Println(err)
          return
      }
      defer resp.Body.Close()

      body, _ := ioutil.ReadAll(resp.Body)
      fmt.Println(string(body))
  }
  ```

  ```java Java theme={"system"}
  import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.net.HttpURLConnection;
  import java.net.URL;

  public class Main {
      public static void main(String[] args) {
          try {
              String apiKey = "API_KEY";
              URL url = new URL("https://api.ayrshare.com/api/ads/instagram/campaigns?accountId=1234567890");

              HttpURLConnection conn = (HttpURLConnection) url.openConnection();
              conn.setRequestMethod("GET");
              conn.setRequestProperty("Authorization", "Bearer " + apiKey);

              BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
              String inputLine;
              StringBuffer response = new StringBuffer();

              while ((inputLine = in.readLine()) != null) {
                  response.append(inputLine);
              }
              in.close();

              System.out.println(response.toString());
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  ```

  ```ruby Ruby theme={"system"}
  require 'net/http'
  require 'uri'
  require 'json'

  api_key = "API_KEY"
  uri = URI.parse("https://api.ayrshare.com/api/ads/instagram/campaigns?accountId=1234567890")

  request = Net::HTTP::Get.new(uri)
  request["Authorization"] = "Bearer #{api_key}"

  response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
    http.request(request)
  end

  puts JSON.parse(response.body)
  ```
</RequestExample>

<ResponseExample>
  ```json 200: Thành công theme={"system"}
  {
      "status": "success",
      "campaigns": [
          {
              "accountId": "8501481455633",
              "boostedObjectId": "67263320208733",
              "budgetRemaining": 0,
              "buyingType": "AUCTION",
              "campaignId": "1202176707545833",
              "configuredStatus": "ACTIVE",
              "created": "2025-03-26T19:42:43-0400",
              "dailyBudget": 0,
              "effectiveStatus": "ACTIVE",
              "endDate": "2026-03-28T18:30:00-0400",
              "lifetimeBudget": 0,
              "metrics": {},
              "name": "API Post - DE6gpw8kxlonHy6eb33 - 2025-03-26T23:42:43",
              "spendCap": 0,
              "startDate": "2026-03-26T18:30:00-0400",
              "status": "ACTIVE"
          }
      ],
      "count": 1,
      "lastUpdated": "2025-03-27T00:57:15.339Z",
      "nextUpdate": "2025-03-27T01:08:15.339Z"
  }
  ```

  ```json 400: Lỗi chiến dịch quảng cáo theme={"system"}
  {
    "action": "get ad campaigns",
    "status": "error",
    "code": 367,
    "message": "Error getting ad campaigns. Please verify you have an active ad campaign account."
  }
  ```
</ResponseExample>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.