User Agreement for the use of the Yandex.Direct Service API. Dependent types using the example of interaction with the Yandex.Direct API Programs for the Yandex Direct api

In this course we will look at service for managing bets in Direct R-broker- http://r-broker.ru/.

There are many similar services. R-broker is one of the leaders on the market.

You can use the service for free if you create a campaign in their account. Just contact them and they will create a new clean account for you (this will be a sub-account of their main agent account).

If you want to connect the service to your account, there is a tariff schedule. Prices for using the service’s capabilities depend on the number of phrases and adjustments.

How does R-broker work?

The R-broker works through the Direct API: http://direct.yandex.ru/help/?id=1113180

It connects to the campaign and has access to bid fields.

The service makes up to 96 automatic corrections per day (every 15 minutes).

According to Direct help, new rates are activated from 5 to 60 minutes. But the average processing time for this action is 10 minutes!

The meaning of R-broker

1. Anti-slip protection

The P-broker protects against support/support (can be called differently).

Let's look at it with an example.

1 special = $5
2 specials = $2
entrance to special = 0.5$

You show up in 1st place.

Your amount debited per click is $2.01.

The competitor in the 2nd position takes you and supports you, sets a bid of $4.99.

All. Now a click costs you $5, not $2.01.

When you have hundreds of phrases in your campaign, you will never be able to control the occurrence of such situations yourself..

Now some robots already have a similar function.

Example - www.magazion.ru.

Based on the chosen strategy, "Magazion" attacks competitors' bids, setting its own, higher bids. The amount of the attack premium depends on the aggressiveness setting (can be set for the entire advertising campaign or for individual phrases).

Well, all adequate modern robots have a protection function.

Similar situations arise in highly competitive fields all the time.

For example - plastic windows, website creation, etc.

Without automating bids through the API, Kazakhstan cannot be truly successful in these areas.

2. Bid management

R-broker is a robot. He monitors the correct implementation of the chosen strategy.

An R-broker is sometimes simply irreplaceable.

The main feature is holding positions without relegation.

Prices rise and fall throughout the day.

If you want to be special at the entrance, we can manually set the rates in the Direct interface for entering the block.

Any fluctuation of 1 cent and we'll be out of there.

We will initially supply more (within our limits) - subsidies are possible.

We can sit all day and adjust the rates ourselves, but we will soon find ourselves in a mental hospital.

The P-broker himself can adjust rates several times an hour.

While competitors' rates change automatically via API many times a day, these people change them manually once a day in the morning. Not equal competition at all.

Nuances

You cannot connect the P-broker to Direct's auto-strategies, because Bidding fields are not available.

The P-broker is ideally used for the highest available position (he simply sets the rate the right place) and entrances to blocks of min. price.

Autobroker Direct will always lower the rate to the minimum possible right now and right here.

The autobroker and the strategy in Direct are of decisive importance in determining the position in the search.

Here's what's bad - the P-broker sometimes takes a long time to load.

Setting up an R broker

A P-broker may seem complicated at first glance. But, I assure you, there is nothing complicated about it.

If you don’t yet understand very well how Direct works, then until you understand, it’s better not to read further, otherwise it will be very difficult to understand. It's better to study past topics again.

Instructions for the R-broker are required to be read!

There is a lot of unnecessary stuff in the P-broker. I will write what is worth paying attention to.

Event Logs / Statistics and Analytics

I never look at statistics through a P-broker. The magazine is sometimes useful, sometimes not.

These are mediocre sections. You can just ignore them now.

Control options

Use the slider (on the left) to enable control and set a schedule for adjusting rates. We check the boxes for the time at which your advertisement runs.

Campaign quality control

It's better not to touch anything.

Recreating a phrase for a low CTR is generally a path to the grave.

We need to treat the problem, not recreate it. Yandex remembers everything.

Automatic connection of new phrases to control

If the tactics are the same for the entire Republic of Kazakhstan, then it’s possible. And if not, then you need to include each phrase yourself.

RK tactics settings

R-max is the maximum price we are willing to pay per click. Not the one that will be in the Direct interface. This information is specifically for the P-broker.

General Settings

Check the second box: “Always set a bid no lower than the minimum bid for display on search.”

I usually turn off the first option.

By including point 3, we will not have an r-max limitation and the rate can be set even at $50 - the main thing is that the budget allows it. To be safe, it’s better not to turn it on.

By the way, $50 is the maximum allowed bet in Direct. Horror. I don’t know who is willing to pay that much for 1 click. Are you ready?

Changing options for all phrases in the campaign

Here you can set general tactics.

Read more about strategies in the instructions.

Basic tactics:

1>2>3 (we occupy a certain place, fall onto the closest one from below)

1>G>D(we take a place within the block, fall into the adjacent block)

The rest are not really needed. They repeat these tactics to some extent.

Example

Let's imagine that we have a tactic in the Direct interface - enter a block of minutes. price (special + guarantee).

We set up the P-broker for 1>G>D CP (special placement) with some R-max.

As a result, everything that can be shown will be shown in the specialist (at the entrance), if it crashes, then it will be guaranteed at the entrance.

Everything that is guaranteed, as soon as possible, breaks through into special.

Economically, angrily.

Remember: a well-tuned advertising campaign is very easy to ruin during a search, so tactics and proper launch are very important.

This Agreement governs the relationship between you (hereinafter referred to as you or the User) and YANDEX LLC (hereinafter referred to as Yandex) regarding the use of the API (hereinafter referred to as the API) of the Yandex.Direct Service (hereinafter referred to as the Service).

Yandex provides you with the opportunity to use the Service API to manage advertising campaigns using Applications that interact with the Service, as well as use the API in other ways that do not contradict this Agreement. The use of the API within the Service is governed by this Agreement, the Service Offer located at , and the Yandex User Agreement, which is available at: .

By using the API, you hereby agree to all the terms of this Agreement and the documents specified above and undertake to comply with them or stop using the API.

For the purposes of this Agreement, the following terms are used:

    API Service "Yandex.Direct", API- software interface for interaction of Applications (as this term is defined below) with the Yandex.Direct Service.

    API Key (OAuth token)- a unique identifier issued to the User, allowing access to the functions of the Service.

API Terms of Use:

1. Your safety.

You are responsible for the safety of your API key, as well as for everything that is done on the Service using the Application and API key you use. All actions in the Service performed using your API key are considered to be performed by you. You agree that you must immediately notify Yandex of any unauthorized (not authorized by you) access to your API key and/or any breach of security. Yandex is not responsible for possible loss or change of data that may occur due to your violation of the provisions of this part of the PS. Yandex encourages you to use all measures to ensure the security of the API, including measures to maintain the confidentiality of the API key.

2. Automated access.

You agree that, with the exception of Applications for interacting with the API, you are prohibited from using other means of automated access (robots, etc.) to the Service.

3. Monitoring.

You understand and agree that Yandex monitors all activity using the API and may collect and analyze statistics on user actions performed using the API.

4. Guarantee of access.

You agree that the terms of service (including the API) may be changed by Yandex at any time without prior notice to users. Therefore, Yandex does not guarantee the constant availability of the Service (including the API) or any of its components. The Services (including API) are provided “as is”. Yandex does not guarantee that the Service or its components (including API) meet the User’s goals and expectations, or that it will operate uninterruptedly or without errors. Yandex is not responsible for your or other users’ actions performed on the Service using the API. Yandex does not compensate for any damage, direct or indirect, caused to the User or third parties as a result of the use or inability to use the Service or its individual components (including API).

You agree that Yandex may suspend or completely close access to the API, change protocols and access methods without giving reasons and without liability on its part. You are responsible for the security of all your data and should be prepared to manage campaigns through the web client interface.

5. Limitations.

You agree that Yandex may, at its discretion, set restrictions (quota) on the use of the API or its individual components, depending on many indicators, including, among other things, the volume of services provided to the Application User, technical indicators of the advertising campaign (average CTR, availability advertisements rejected for moderation, etc.).

The rules for applying such restrictions are described in the “Questions and Answers” ​​located at the “API” link in your account.

If you use an Application that does not meet the requirements set out in the User Agreement for Developers, Yandex reserves the right to limit and/or deny your access to the API.

You also bear all responsibility and risk of adverse consequences associated with restricting and\\or prohibiting Applications' access to the API on the grounds established in the User Agreement for Developers.

6. Third parties.

In the event that you use the API to manage advertising campaigns of third parties based on a contract or other agreement between you, you must understand that all data relating to the accounts of such clients and other information relating to advertising campaigns such customer transactions using your API key are considered confidential; You do not have the right to use them yourself or transfer them to third parties without the written consent of their owners.

If you provide access to the API to any third parties (including by creating for them an account associated with your account) You are solely responsible for all actions of such third parties as if they were your own.

7. Validity of this agreement.

Yandex reserves the right to suspend this agreement with respect to you if you do not comply with its terms. From the moment of such suspension, you must cease further use of the API.

8. Final provisions.

This Agreement and all relations related to the use of the Service and API are governed by the laws of the Russian Federation.

All claims related to the use/inability to use the API within the Service should be sent to: [email protected].

Yandex may change the text of this Agreement and/or any other terms of use of the Service at any time without notifying the User. Current text of this Agreement is located at: .

_____________________________

Date of publication 04/05/2019

Previous version of the document: .

Previous version of the document: .

Hello.

The popularization of dependent types for programming is greatly facilitated by the Servant library, which is used both to provide a typed API (servant-server) and to write queries to an existing one (servant-client). We will use this library (an explanation of how it works is beyond the scope of this post; those interested can read the report). However, the matter will not be limited to the dependent types built into Servant, and we will add more of our own.

Plan

We will describe several basic entities of the Yandex.Direct API: method (add, get), operation, result of the operation, object (names of dictionaries, advertisements, campaigns) and define a dependently typed function that allows you to call any method parameterized by some object and accept a response whose type depends on the method called and the type of the object.

Operations

Objects

The Yandex.Direct API is very extensive: it can be used to process ads, ad groups, campaigns, extensions, keywords and much more. We will write a generic function that will allow us to pass any of these objects to the called method.

First a couple of examples. Announcements:

Campaigns:

The address for processing requests related to ads is “https://api.direct.yandex.com/json/v5/ads”, and the address for processing requests related to campaigns is “https://api. direct.yandex.com/json/v5/campaigns.” All other objects also have their own addresses for processing requests. So let's create a type class

That is, each object must be serializable to JSON so that it can be sent over the network, and have a name that forms part of the address for requests.

API

Let's describe the Direct API using the tools provided by Servant:

a is the type of the parameter of the called method, r is the type of the returned result. The operation is automatically serialized to JSON, the result is automatically deserialized from JSON.

We also need a Direct-specific config:

And we can finally put everything together and define the main function for communicating with the Direct API:

(In newer versions, Servant Manager is part of ClientM, but at the time of writing the latest LTS snapshot on Stackage uses old version). perform accepts a Direct-specific config, a connection manager, a method to be called in singleton form, and an object to be passed to the method. From the signature of perform we can see that the type of the return value (ResultOf m a) really depends on the method called (m in SMthod m) and on the type of the parameter (a) passed to it. Otherwise we just use the basic functionality provided by Servant.

Conclusion

Using a dependently typed Servant, you can declaratively describe the API, and eliminate the need to manually serialize and deserialize data. However, the types of data that comes in response to a request may depend on the contents of the request, but dependent types here also allow you to express all the necessary invariants.