
import SurveyFields from "../../../src/reference/subbly-sdk/types/Survey.mdx";

<SdkPage group="surveys" />

<Method id="load" signature="subbly.surveys.load(surveyId, params?, headers?)">

Loads a survey with its questions, answers and styling. A survey belongs to a
plan: read `plan.survey.id` on the plan the customer chose, load the survey,
then send the answers as `options` on the cart item.

<Params>
  <Param name="surveyId" required type="number">
    ID of the survey.
  </Param>

  <Param name="params" optional type="SurveyResourceParams">
    Extra data to include.
    <Properties label="params">
      <Param name="expand" optional type="string[]">
        Relations to include. `questions.answers.product.parent` loads the
        product behind each offer and plan answer, with its parent product.
      </Param>
    </Properties>
  </Param>

  <Param name="headers" optional type="SurveyRequestHeaders">
    Extra request headers. Set `x-currency` to price the answers in another
    currency. Without it the SDK sends the currency from `subbly.setCurrency`.
  </Param>
</Params>

<Returns type="Promise<Survey>">
The survey.
<Properties label="survey" collapsed>
  <SurveyFields />
</Properties>
</Returns>

<Example>

```js title="Load a survey"
const survey = await subbly.surveys.load(123, {
  expand: ['questions.answers.product.parent']
})
```

```js title="Answer it and add the item to the cart"
const survey = await subbly.surveys.load(plan.survey.id)
const [question] = survey.questions

await subbly.cart.addItem({
  productId: plan.id,
  quantity: 1,
  options: [{ questionId: question.id, answers: [{ id: question.answers[0].id }] }]
})
```

</Example>

</Method>
