# Запрос кампаний

Для получения кампании из API Gravity Field необходимо отправить запрос в endpoint choose. В запросе должен быть указан селектор кампании, который вы задали при создании кампании.

{% hint style="info" %}
В случае гибридной интеграции возможно использовать choose-запрос с пустым селектором для получения актуальных значений user.slid и session.sl
{% endhint %}

## POST /ssapi/choose

> Get the chosen variations for one or more campaigns.

```json
{"openapi":"3.0.3","info":{"title":"Gravity Field SSAPI","version":"1.0.0"},"servers":[{"url":"https://evs.gravityfield.ai"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"API-KEY"}},"schemas":{"user":{"type":"object","description":"User ID. A Gravity Field-generated identifier is used, and managed via cookies. For a new user, send this object empty.","properties":{"id":{"description":"External user identification","type":"string"},"slid":{"description":"The user ID assigned to visitors by Gravity Field. For a new user, send this param empty.","type":"string"},"slid_server":{"description":"The user ID assigned to visitors by Gravity Field. For a new user, send this param empty.","type":"string"}}},"session":{"type":"object","description":"Session ID. A Gravity Field-generated identifier is used. For new sessions, send this object empty.","properties":{"custom":{"description":"External session identification, used only external user id","type":"string"},"sl":{"description":"Pass the value of the _slsession cookie if it exists. Otherwise, a new session identifier will be created by Gravity Field and returned in the response.","type":"string"}}},"context":{"type":"object","description":"The request's context.","properties":{"page":{"description":"Data for the page currently being browsed.","type":"object","properties":{"type":{"description":"Page type. Must be upper case. Valid values are HOMEPAGE, CATEGORY, PRODUCT, CART, SEARCH and OTHER.","type":"string","enum":["HOMEPAGE","PRODUCT","CART","CATEGORY","SEARCH","OTHER"]},"data":{"description":"Additional data for non-homepage pages The SKU for a PRODUCT page, the category for a CATEGORY page, SKUs for the CART page, and query string for SEARCH","type":"array","items":{"type":"string"}},"lng":{"description":"Page locale code, such as ru_RU.","type":"string"},"location":{"description":"The current location. URL (for web), location (for SPA), or screen name (for mobile apps). Enables targeting the current page/screen.","type":"string"},"referrer":{"description":"The previous location. URL (for web), location (for SPA), or screen name (for mobile apps). Enables targeting the previous page/screen.","type":"string"}},"required":["type","data","location"]},"device":{"description":"Data for the served device.","type":"object","properties":{"userAgent":{"description":"For web clients, the browser user-agent string. If not passed, the API gateway checks for the header in the HTTPS request.","type":"string"},"ip":{"description":"The client IP address, for geolocation-based targeting and audience building. If not passed, the caller IP is used.","type":"string"}}}},"required":["page"]}},"responses":{"UnauthorizedError":{"description":"Access token is missing or invalid"},"ValidationError":{"description":"Error validation request data","content":{"application/json":{"schema":{"type":"object","properties":{"code":{"type":"integer"},"message":{"type":"string"},"type":{"type":"string"}}}}}}}},"paths":{"/ssapi/choose":{"post":{"tags":["SSAPI"],"description":"Get the chosen variations for one or more campaigns.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"user":{"$ref":"#/components/schemas/user"},"session":{"$ref":"#/components/schemas/session"},"context":{"$ref":"#/components/schemas/context"},"selector":{"type":"object","description":"Campaigns to choose variations for.","properties":{"names":{"description":"The list of selectors that are eligible for this page. A selector represents a technical name for a campaign.","type":"array","items":{"type":"string"}},"groups":{"description":"Call a group of selectors instead of listing each selector individually.","type":"array","items":{"type":"string"}},"args":{"type":"object","description":"Real-time filters for recommendation results, based on data obtained within the session.","properties":{"recs campaign":{"description":"Real-time filter for a single selector. The object key should corresponds to a selector name defined under selector.names.","type":"object","properties":{"realtimeRules":{"description":"A list of realtime filtering rules.","type":"array","items":{"description":"Multiple rules inside the same condition use the AND operator between them","type":"object","properties":{"id":{"description":"The unique ID number for every rule. This ID is used in the API response (if 2 rules have the same ID, the second rule is dropped).","type":"integer"},"type":{"description":"Valid values are include, exclude.","type":"string","enum":["include","exclude"]},"slots":{"type":"array","description":"All or specific slot positions. The first slot is in position 0.","items":{"type":"integer"}},"query":{"type":"object","description":"The filtering query.","properties":{"conditions":{"description":"The realtime rule's query conditions. Multiple rules inside the same condition use the AND operator between them","type":"array","items":{"type":"object","properties":{"field":{"type":"string","description":"Field within the returned results to apply the query for."},"arguments":{"description":"A list of arguments for a query condition. Multiple arguments inside the same condition use the OR operator between them","type":"array","items":{"type":"object","properties":{"action":{"type":"string","description":"Condition types for filtering recommendations.","enum":["equal","not_equal","more","more_or_equal","less","less_or_equal","contains"]},"value":{"description":"Parameter for filter value by condition. Multiple values inside the same condition use the OR operator between them","type":"array","items":{"type":"string"}}},"required":["action","value"]}}},"required":["field","arguments"]}}}}}}}}},"maxProducts":{"description":"Product count 1 to 50, overwrite by variation setting","type":"integer"}}}},"required":["names"]},"options":{"type":"object","description":"Request configuration parameters.","properties":{"isImplicitPageview":{"description":"Determine whether to report a new pageview with the given context. Default is false. Set to true to report a new pageview with the given context. Keep as false if the Gravity Field script is implemented on the page. It reports the new pageview from the browser.","type":"boolean","default":false},"returnAnalyticsMetadata":{"description":"Return additional metadata (display names & IDs for all entities). Useful for reporting to analytics tools. Set to true to return additional metadata (display names & IDs for all entities) for reporting to analytics tools.","type":"boolean","default":false},"recsProductData":{"description":"You can use either the fieldFilter param to ask for specific attributes from the feed, or the skusOnly param to to fetch only the SKUs.","type":"object","properties":{"skusOnly":{"description":"To reduce the size of the response, you can limit it so that it only includes the SKUs.","type":"boolean"},"fieldFilter":{"description":"Specify the fields you need in the recommendation campaign response by using the fieldFilter parameter. Simply send an array of strings of the relevant fields, and only those fields and values are sent back.","type":"array","items":{"type":"string"}}}}}}},"required":["user","session","context","selector"]}}}},"responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{"type":"object","properties":{"user":{"type":"object","properties":{"slid":{"type":"string","nullable":true,"description":"If a user has been created then the uid is returned. Set cookies in the frontend"}}},"session":{"type":"object","properties":{"sl":{"type":"string","nullable":true,"description":"If a session has been created then the ses is returned. Set cookies in the frontend"}}},"choices":{"type":"array","description":"The chosen variation for each campaign.","items":{"type":"object","properties":{"id":{"description":"Campaign id","type":"string"},"name":{"description":"Campaign name","type":"string"},"type":{"description":"Campaign type","type":"string","enum":["DECISION","RECS_DECISION"]},"decisionId":{"description":"decision event token","type":"string"},"variations":{"description":"Selected variation","type":"array","items":{"type":"object","properties":{"id":{"description":"Variation id","type":"string"},"name":{"description":"Variation name","type":"string"},"payload":{"type":"object","properties":{"type":{"description":"Type payload","type":"string","enum":["CUSTOM_JSON","RECS"]},"data":{"type":"object","properties":{"custom":{"description":"Custom json code","type":"object"},"slots":{"description":"Recs products","type":"array","items":{"type":"object","properties":{"sku":{"type":"string"},"productData":{"type":"object"},"slotId":{"description":"Slot event token","type":"string"}}}},"count_pages":{"description":"All count pages by filter in PLP","type":"integer"},"page":{"description":"Current page in PLP","type":"integer"},"count":{"description":"Count all products in PLP","type":"integer"}}}}}}}}}}}}}}}},"401":{"$ref":"#/components/responses/UnauthorizedError"},"422":{"$ref":"#/components/responses/ValidationError"}}}}}}
```
