Documentation / API / campaigns_rebuild_counts

campaigns_rebuild_counts

POSThttps://api.oppalerts.com/v1/campaigns/rebuild_counts

Asks for the stored daily counts of one campaign to be counted again.

What it does

The tool asks for the stored daily counts of one campaign to be counted again, for example after a change to its organizations.

The call only submits the request. A background job calculates the counts in the next few minutes. The Dashboard tab of Edit Campaign and campaigns_dashboard show the new counts when it is done.

A second call while the job waits or runs changes nothing.

Who May Call It

  • The account owner, an account editor, or a campaign editor of this campaign. An account viewer or a campaign viewer gets the error no_access.
  • The token needs the scope api:write, and api:read as every API route does. Without api:write, the call gets the error forbidden. Authentication says which tokens have it.

Authentication

Send your token in the Authorization: Bearer header. The API overview explains how to get a token. The API also accepts the same call at POST /v1/campaigns_rebuild_counts.

Parameters

campaignint, required, 1 to 4294967295
The campaign id, from campaigns_list. It must be a campaign of your account.

Rules

  • campaign is required. The tool takes no other field.
  • The tool does not perform the lengthy counting work during the call.
  • The campaign must be active and finalized. An archived campaign is refused with campaign_archived. A campaign that is not finalized is refused with not_finalized, because a campaign has no daily count before it is finalized.

Strict Rules

  • A field that is not in the list above is refused. The answer is HTTP 400 with the error code bad_param. The error names the field: "<field> is not a field of this tool."
  • A bad value is refused, and the error names the field. A bad value is a value of the wrong type, a number with a fraction for a whole-number field, a value out of its range, a value that is not in its list, or an empty text, list, or object. A required field that you do not send is refused too. To send no value for an optional field, leave the field out. No field has a default value, and the tool never changes a value that you send.
  • An error about the format of a call, such as a refused field, names the field. Its message ends with one sentence: "Read the documentation at https://oppalerts.com/docs for the correct format." Every other error, such as forbidden below, has only its own sentence.

Response fields

job_statestring
The state of the count job: pending while the job waits, running while it counts, and done or failed after it ran.

Example

Request

curl -X POST https://api.oppalerts.com/v1/campaigns/rebuild_counts \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"campaign": 124}'

Response

The response is shown in full.

{
  "job_state": "pending"
}

Errors

An error has an HTTP status and a JSON body with error, the error code, and error_description, the message. An example: a call with a token that does not have the scope api:write. This answer also has a WWW-Authenticate header with error="insufficient_scope" and the scopes that the call needs.

HTTP/1.1 403 Forbidden
WWW-Authenticate: Bearer error="insufficient_scope", scope="api:read api:write", resource_metadata="https://api.oppalerts.com/.well-known/oauth-protected-resource/v1", error_description="This token cannot change data. Make a new API token with edit permissions on the API tokens page, or connect the app again and allow changes."
Content-Type: application/json

{
  "error": "forbidden",
  "error_description": "This token cannot change data. Make a new API token with edit permissions on the API tokens page, or connect the app again and allow changes."
}

The error codes of this tool, each with its HTTP status and its sentence:

  • bad_param (HTTP 400): A parameter is missing or has a wrong value. The sentence names it.
  • no_campaign (HTTP 404): That campaign is not in this account.
  • forbidden (HTTP 403): This token cannot change data. Make a new API token with edit permissions on the API tokens page, or connect the app again and allow changes.
  • no_access (HTTP 403): You have read permissions for this campaign.
  • db_error (HTTP 500): The change could not be saved. Nothing was changed.
  • campaign_archived (HTTP 409): Not started: this campaign is archived. Make it active first.
  • not_finalized (HTTP 409): Not started: this campaign is not finalized. A campaign has no daily count before it is finalized.

Limits

  • This tool has its own daily count for the account. When the count is used up, the call is refused with daily_limit (HTTP 429). account_calls_left shows the calls left today and when the count resets.
  • A refused call does not use the daily count of this tool.
  • This tool is not an index search. It does not use the daily count of index searches.
  • Only one change runs at a time per account. A call made while another change is running for the account is refused with one_at_a_time (HTTP 429) and uses no daily call. Send it again after a few seconds.

Same tool in MCP

The MCP tool is campaigns_rebuild_counts. See campaigns_rebuild_counts in MCP.