# Initiate Survey — Pidj

> Triggers a pre-configured text survey to a specific contact. Requires the contact's information and the survey ID. See the documentation.

- Key: `pidj-initiate-survey`
- Type: Action (Write)
- Version: 0.0.2
- App: Pidj (`pidj`) — https://pipedream.com/apps/pidj.md
- This page (HTML): https://pipedream.com/apps/pidj/actions/initiate-survey
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/pidj/actions/initiate-survey/initiate-survey.mjs

## Description

Triggers a pre-configured text survey to a specific contact. Requires the contact's information and the survey ID. [See the documentation](https://pidj.co/wp-content/uploads/2023/06/Pidj-API-Technical-Document-v3-1.pdf).

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `surveyId` | `string` | Yes | The ID of the survey to be triggered. Options are loaded from the connected account. |
| `contactId` | `string` | Yes | The ID of the contact. Options are loaded from the connected account. |
| `fromNumber` | `string` | No | Phone number to send from; this will determine which group the message sends from, and must be an active number from one of your groups. This must be in E.164 format, e.g., +18885552222 |
| `groupId` | `string` | No | The Id of the group. Options are loaded from the connected account. |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "pidj",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "pidj-initiate-survey",
  arguments: {
    surveyId: "Survey ID",
    contactId: "Contact ID",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "pidj-initiate-survey",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    pidj: { authProvisionId: "apn_xxxxxxx" },
    surveyId: "Survey ID",
    contactId: "Contact ID",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "pidj-initiate-survey",
    "configured_props": {
      "pidj": { "authProvisionId": "apn_xxxxxxx" },
      "surveyId": "Survey ID",
      "contactId": "Contact ID"
    }
  }'
```

---

- App: https://pipedream.com/apps/pidj.md · All apps: https://pipedream.com/apps
