> ## Documentation Index
> Fetch the complete documentation index at: https://docs.depict.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect an Instagram account from an OAuth code

> Finishes Instagram's OAuth flow: exchanges the code for a long-lived token and stores it encrypted as the merchant's Instagram login, replacing any previous one. Only useful right after the OAuth dialog redirects back; codes are single-use. Returns JSON `null`.



## OpenAPI

````yaml /api-reference/openapi/lite.json post /instagram/{merchant_id}/account/connect
openapi: 3.1.0
info:
  title: Search & Merchandising API
  version: 1.0.0
  description: >-
    REST API behind Depict: Search & Merchandising, the native Shopify app:
    onboarding, collections, boost & bury, dashboards, A/B testing and
    multi-store management. Endpoints are served under the /api/lite prefix and
    are authenticated with the Shopify session token that App Bridge issues to
    the embedded app.
servers:
  - url: /api/lite
security:
  - ShopifySessionToken: []
paths:
  /instagram/{merchant_id}/account/connect:
    post:
      summary: Connect an Instagram account from an OAuth code
      description: >-
        Finishes Instagram's OAuth flow: exchanges the code for a long-lived
        token and stores it encrypted as the merchant's Instagram login,
        replacing any previous one. Only useful right after the OAuth dialog
        redirects back; codes are single-use. Returns JSON `null`.
      operationId: instagramAccountConnect
      parameters:
        - schema:
            type: string
            description: Lite merchant id, e.g. `shopify-<shop id>`.
          required: true
          description: Lite merchant id, e.g. `shopify-<shop id>`.
          name: merchant_id
          in: path
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/InstagramConnectRequest'
      responses:
        '200':
          description: Saved; the body is JSON `null`.
          content:
            application/json:
              schema:
                type: 'null'
        '400':
          description: >-
            The body failed the schema, Instagram is not configured on this
            deployment, or Instagram refused the code (`detail` says which).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Detail'
        '401':
          description: Not authenticated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Detail'
        '403':
          description: Authenticated, but this identity may not call the API.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Detail'
        '404':
          description: Merchant not found for this caller.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Detail'
        '415':
          description: Content-Type is not application/json.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Detail'
        '500':
          description: Internal error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Detail'
components:
  schemas:
    InstagramConnectRequest:
      type: object
      properties:
        code:
          type: string
          minLength: 1
          description: >-
            The single-use authorization `code` Instagram's OAuth dialog
            appended to the redirect URL.
        redirect_uri:
          type: string
          description: The redirect URI the OAuth dialog was opened with.
      required:
        - code
        - redirect_uri
    Detail:
      type: object
      properties:
        detail:
          type: string
      required:
        - detail
      description: 'Every 4xx/5xx body: `{detail}`.'
  securitySchemes:
    ShopifySessionToken:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        Shopify App Bridge session token of the embedded Depict: Search &
        Merchandising app. The shop in the token determines the merchant;
        merchant_id parameters must belong to that shop.

````