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

# Exchange a granted connection for an access token

> For code running as the resource only (the app’s own token, or the automation runtime token). The connection must be granted to the resource.



## OpenAPI

````yaml /swagger.json post /credential/resource/{resourceType}/{resourceId}/connection-token
openapi: 3.0.0
info:
  version: 1.0.0
  title: Teable App
  description: Manage Data as easy as drink a cup of tea
  x-logo:
    backgroundColor: '#F0F0F0'
    altText: Teable logo
servers:
  - url: https://app.teable.ai/api
security: []
tags:
  - name: base
    x-group: project
  - name: base node
    x-group: project node
  - name: base-share
    x-group: project-share
paths:
  /credential/resource/{resourceType}/{resourceId}/connection-token:
    post:
      tags:
        - credential
      summary: Exchange a granted connection for an access token
      description: >-
        For code running as the resource only (the app’s own token, or the
        automation runtime token). The connection must be granted to the
        resource.
      parameters:
        - schema:
            type: string
            enum:
              - automation
              - app
          required: true
          name: resourceType
          in: path
        - schema:
            type: string
          required: true
          name: resourceId
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                alias:
                  type: string
                  pattern: ^[A-Z][A-Z0-9_]{0,63}$
                credentialId:
                  type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  accessToken:
                    type: string
                  provider:
                    type: string
                    enum:
                      - slack
                      - gmail
                      - outlook
                      - airtable
                      - googleSheet
                  credentialId:
                    type: string
                  alias:
                    type: string
                required:
                  - accessToken
                  - provider
                  - credentialId
                  - alias
      security:
        - bearerAuth: []
      x-codeSamples:
        - lang: Shell
          source: |-
            curl --request POST \
              --url https://app.teable.ai/api/credential/resource/%7BresourceType%7D/%7BresourceId%7D/connection-token \
              --header 'Authorization: Bearer REPLACE_BEARER_TOKEN' \
              --header 'content-type: application/json' \
              --data '{"alias":"string","credentialId":"string"}'
        - lang: JavaScript
          source: >-
            const url =
            'https://app.teable.ai/api/credential/resource/%7BresourceType%7D/%7BresourceId%7D/connection-token';

            const options = {
              method: 'POST',
              headers: {
                Authorization: 'Bearer REPLACE_BEARER_TOKEN',
                'content-type': 'application/json'
              },
              body: '{"alias":"string","credentialId":"string"}'
            };


            try {
              const response = await fetch(url, options);
              const data = await response.json();
              console.log(data);
            } catch (error) {
              console.error(error);
            }
        - lang: Node.js
          source: >-
            const http = require('https');


            const options = {
              method: 'POST',
              hostname: 'app.teable.ai',
              port: null,
              path: '/api/credential/resource/%7BresourceType%7D/%7BresourceId%7D/connection-token',
              headers: {
                Authorization: 'Bearer REPLACE_BEARER_TOKEN',
                'content-type': 'application/json'
              }
            };


            const req = http.request(options, function (res) {
              const chunks = [];

              res.on('data', function (chunk) {
                chunks.push(chunk);
              });

              res.on('end', function () {
                const body = Buffer.concat(chunks);
                console.log(body.toString());
              });
            });


            req.write(JSON.stringify({alias: 'string', credentialId:
            'string'}));

            req.end();
        - lang: Python
          source: >-
            import http.client


            conn = http.client.HTTPSConnection("app.teable.ai")


            payload = "{\"alias\":\"string\",\"credentialId\":\"string\"}"


            headers = {
                'Authorization': "Bearer REPLACE_BEARER_TOKEN",
                'content-type': "application/json"
            }


            conn.request("POST",
            "/api/credential/resource/%7BresourceType%7D/%7BresourceId%7D/connection-token",
            payload, headers)


            res = conn.getresponse()

            data = res.read()


            print(data.decode("utf-8"))
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````