POST/{resource-id}

Adds a new object to the specified resource.

Request format

POST https://jsonapi.partner2.yandex.com/vX/{resource-id}

Parameter

Description

resource-id

ID of the resource to add a new object to.

Format of the request body

JSON

{
  "data": 
    {
      "type": "{string}",
      "attributes": {
        "brands": [
          {
            "bid": "{string}",
            "blocked": {boolean},
            "cpm": {integer}
          },
          {
            ...
          }
        ],
        "client_id": {integer},
        "email": "{string}",
        "excluded_domains": ["{string}"],
        "excluded_phones": ["{string}"],
        "geo": [
          {
            "id": "{string}",
            "cpm": {integer}
          },
          {
            ...
          }
        ]
      }
    }
}           

When creating ad units via the API, make sure to explicitly specify the display ad design settings.

Example:

 
"design_templates":[
  {
    "caption":"Media design",
    "type":"media",
    "design_settings":
    {
      "filterSizes":false,
      "horizontalAlign":true
    }
  }
],
            

Parameters of the request body

  • data * Object with parameters.

    • type * The resource type.

    • attributes * Object parameters.

      Restriction.

      The allowed values depend on the resource that the object belongs to. They are listed in the editable_fields parameter for the GET/{resource-id}/{object-id} operation. As an example, some of the parameters are shown below.

      • brands Brands to set for the current object.

        • bid The minimum bid required for showing the brand (in rubles).

        • blocked The brand is blocked (true or false).

        • cpm The minimum CPM required for showing the brand (in rubles).

      • client_id Client ID.

      • email The client's email address.

      • excluded_domains Domains to exclude.

      • excluded_phones Phones to exclude.

      • geo Regional targeting to set for the current object.

        • id The region ID. Use the GET/{resource-id} operation to get the region.

        • cpm The minimum CPM required for showing the brand in the current region (in rubles).

* Required

The general structure of the response is given below. The elements may appear in a different order. The structure may contain internal parameters that are not described in the table.

Response format

JSON

{
  "data":
  {
      "relationships": {
        "{string}": {
          "links": {
            "related": "{string}",
            "self": "{string}"
          }
        },
        ...
      },
      "id": "{string}",
      "type": "{string}",
      "attributes": {
      },
      "links": {
        "self": "{string}"
      }
  },
  "links": {
    "first": "{string}",
    "next": "{string}",
    "prev": "{string}",
    "self": "{string}",
    "last": "{string}"
  }
}        

Response parameters

  • data Information about the created object.

    • relationships Related resources and objects.

      • links References to objects related to the current object.

        • related Reference to a list of related objects with parameters.

        • self Reference to a list of related objects.

    • id Object ID.

    • attributes Array of object parameters. The list of parameters depends on the resource type. As an example, some of the parameters are shown below.

      • actions Actions available for this object.

      • brands Brands set for this object.

        • bid The minimum bid required for showing the brand (in rubles).

        • blocked The brand is blocked (true or false).

      • client_id Client ID.

      • editable_fields Parameters of the current object that can be edited.

      • email The client's email address.

      • excluded_domains Excluded domains.

      • excluded_phones Excluded phone numbers.

      • geo Regional targeting set for this object.

        • id The region ID. Use the GET/{resource-id} operation to get the region.

        • cpm The minimum CPM required for showing the brand in the current region (in rubles).

      • lang Interface language.

      • lastname The client's last name.

      • level The nesting level.

      • login The user's username.

      • midname The user's middle name.

      • multistate The current status of the object.

      • multistate_name Text description of the object's status.

      • name Name of the object.

      • page_id Site ID.

      • parent_id ID of the parent object.

      • regularity Sorting order in the interface.

      • roles The user's roles.

      • status The status of the object. Acceptable values:

                   - sync — Synchronized.

                   - pending — Sending.

    • links Links associated with the object.

      • self Reference to the current object.

Example for JSON

$PI_TOKEN must contain the token value for the partner interface API. For example, the value can start with "a7b8e0-". Make sure also to set your value for page_id.

Request:

curl -v -H "Accept: application/vnd.api+json" \
-H "Content-Type: application/vnd.api+json" \
-H "Authorization: token $PI_TOKEN" \
-X POST \
--data \
  '{
    "data":
    {
      "type":"context_on_site_rtb",
      "attributes":
      {
        "caption":"API-created block",
        "page_id": "636326",
        "site_version": "mobile",
        
        "design_templates":[
          {
            "caption":"Media design",
            "type":"media",
            "design_settings":
            {
              "filterSizes":false,
              "horizontalAlign":true
            }
          },
          {
            "caption":"Standard design",
            "type":"tga",
            "filter_tags":["adaptive","vertical"],
            "is_custom_format_direct": false, 
            "design_settings":
            {
              "name":"adaptive0418",
              "limit":1
            }                    
          }
        ],
        "dsp_blocks":["300x300","300x500","300x600","336x280","100%x250"],
        "blind":0,
        "strategy":1
      }
    }
  }' \
'https://jsonapi.partner2.yandex.com/v1/context_on_site_rtb' | json_pp

Response:

HTTP/1.1 201 Created
Content-Length: 683
Content-Type: application/vnd.api+json
Date: Fri, 13 Nov 2020 11:32:18 GMT
Location: https://jsonapi.partner2.yandex.com/v1/context_on_site_rtb/R-A-636326-3
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff


{
   "data" : {
      "attributes" : {},
      "id" : "R-A-636326-4",
      "links" : {
         "self" : "https://jsonapi.partner2.yandex.com/v1/context_on_site_rtb/R-A-636326-4"
      },
      "relationships" : {
         "context_on_site_campaign" : {
            "links" : {
               "related" : "https://jsonapi.partner2.yandex.com/v1/context_on_site_rtb/R-A-636326-4/context_on_site_campaign",
               "self" : "https://jsonapi.partner2.yandex.com/v1/context_on_site_rtb/R-A-636326-4/relationships/context_on_site_campaign"
            }
         },
         "pages" : {
            "links" : {
               "related" : "https://jsonapi.partner2.yandex.com/v1/context_on_site_rtb/R-A-636326-4/pages",
               "self" : "https://jsonapi.partner2.yandex.com/v1/context_on_site_rtb/R-A-636326-4/relationships/pages"
            }
         }
      },
      "type" : "context_on_site_rtb"
   }
}