# embedding_metadata

key: url
string_value:
https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb


key: _node_content
string_value:
{"id_": "410a09b7-d51c-45ee-a03d-6687a6f457a0", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "814bcd65-485f-440e-a36a-6452fbc67cdf", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "5d9fc69b32c5c60bc934cea2c4d4dc439c559f48db2d7958eeb188136d38e93d", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "808fc37c-0311-437c-b45c-de6b331d89e5", "node_type": "1", "metadata": {}, "hash": "b6afc9f6eeff315579f086f30055e8e7d2391e2b89f79446e7e193156d033725", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 0, "end_char_idx": 3573, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
# GPT Action Library: Canvas LMS

## Introduction

This page provides an instruction & guide for developers building a GPT Action for a specific application. Before you proceed, make sure to first familiarize yourself with the following information: 
- [Introduction to GPT Actions](https://platform.openai.com/docs/actions)
- [Introduction to GPT Actions Library](https://platform.openai.com/docs/actions/actions-library)
- [Example of Buliding a GPT Action from Scratch](https://platform.openai.com/docs/actions/getting-started)

This particular GPT Action provides an overview of how to connect to Canvas (infrastructure.canvas.com), a widely used LMS tool for course material, grading and general education purposes. 

### Value + Example Business Use Cases

**Value**: Users can now leverage ChatGPT's natural language capability to connect directly to Canvas

**Example Use Cases**:
- Query content from LMS 
- Build quizzes
- Create new modules
- Understand topics from assigned courses

## Application Information

### Application Key Links

Check out these links from the application before you get started:
- Application Website: https://canvas.instructure.com/login/canvas 
- Application API Documentation: https://canvas.instructure.com/doc/api/
 

### Application Prerequisites

Before you get started, make sure you go through the following steps in your application environment:
- Ensure you have the access and permissions in Canvas to create an approved integration with an Access Token for testing
- For OAuth connection see here : https://canvas.instructure.com/doc/api/file.oauth.html


![gptactions_canvaslms_approvedintegrations.png](../../../images/gptactions_canvaslms_approvedintegrations.png)


## ChatGPT Steps

### Custom GPT Instructions 

Once you've created a Custom GPT, copy the text below in the Instructions panel. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.


```python
**Context** : You are a helpful friendly university level course helper designed to search across canvas courses to help students and educators, this GPT is intended to help students and teachers understand course material, take quiz's and tests from information stored in canvas.  


**Instructions**
When asked to perform a task, use the available actions via the canvas.infrastructure.com API


You should be professional and verbose with answers, provide clear pedagogical experience for users. 


Offer assistance with tasks around summarizing course material, understanding module and quiz information. 


Ask for clarification when needed to ensure accuracy and completeness in fulfilling user requests. It should also respect user privacy and handle all data securely.


If a user uploads a file, help the user analyze the file before callin the canvas API.

```

### OpenAPI Schema 

Once you've created a Custom GPT, copy the text below in the Actions panel. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.


```python
openapi: 3.1.0
info:
  title: Canvas LMS API
  description: >
    This is the API of the Canvas LMS, providing access to various resources such as accounts, courses, users,
    assignments, quizzes, files, and more.
  version: 1.0.0
servers:
  - url: https://canvas.instructure.com
    description: Canvas LMS Production Server
paths:
  /api/v1/accounts:
    get:
      summary: List accounts
      operationId: listAccounts


key: _node_content
string_value:
{"id_": "808fc37c-0311-437c-b45c-de6b331d89e5", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "814bcd65-485f-440e-a36a-6452fbc67cdf", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "5d9fc69b32c5c60bc934cea2c4d4dc439c559f48db2d7958eeb188136d38e93d", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "410a09b7-d51c-45ee-a03d-6687a6f457a0", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "987862ddb9f34f94f49f79a901463d49db608989ace0cd219450f3c0972e5cf3", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "a318bb57-b545-44ba-915f-4187bb22a777", "node_type": "1", "metadata": {}, "hash": "8f7ad2cf854720b6866d86498ff64a56dd6c3e402b58ce71053dafedfeb5d2ee", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 2005, "end_char_idx": 4429, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
```python
**Context** : You are a helpful friendly university level course helper designed to search across canvas courses to help students and educators, this GPT is intended to help students and teachers understand course material, take quiz's and tests from information stored in canvas.  


**Instructions**
When asked to perform a task, use the available actions via the canvas.infrastructure.com API


You should be professional and verbose with answers, provide clear pedagogical experience for users. 


Offer assistance with tasks around summarizing course material, understanding module and quiz information. 


Ask for clarification when needed to ensure accuracy and completeness in fulfilling user requests. It should also respect user privacy and handle all data securely.


If a user uploads a file, help the user analyze the file before callin the canvas API.

```

### OpenAPI Schema 

Once you've created a Custom GPT, copy the text below in the Actions panel. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.


```python
openapi: 3.1.0
info:
  title: Canvas LMS API
  description: >
    This is the API of the Canvas LMS, providing access to various resources such as accounts, courses, users,
    assignments, quizzes, files, and more.
  version: 1.0.0
servers:
  - url: https://canvas.instructure.com
    description: Canvas LMS Production Server
paths:
  /api/v1/accounts:
    get:
      summary: List accounts
      operationId: listAccounts
      responses:
        "200":
          description: A paginated list of accounts
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Account"
  /api/v1/accounts/{account_id}:
    get:
      summary: Get a single account
      operationId: getAccount
      parameters:
        - name: account_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: Account details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Account"
  /api/v1/courses:
    get:
      summary: List courses
      operationId: listCourses
      responses:
        "200":
          description: A paginated list


key: _node_content
string_value:
{"id_": "a318bb57-b545-44ba-915f-4187bb22a777", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "814bcd65-485f-440e-a36a-6452fbc67cdf", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "5d9fc69b32c5c60bc934cea2c4d4dc439c559f48db2d7958eeb188136d38e93d", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "808fc37c-0311-437c-b45c-de6b331d89e5", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "8f9052e429f5404f056e02965268cae89103612e9248ed3c8f33d3598faf41f2", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "c80a784a-f11c-4303-bc0d-97ff6bfc71f2", "node_type": "1", "metadata": {}, "hash": "1699ee8c932e1fe51530e65a952947fb6a694dd0432f874fffc4e8791dbfee18", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 3599, "end_char_idx": 5182, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
"200":
          description: A paginated list of accounts
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Account"
  /api/v1/accounts/{account_id}:
    get:
      summary: Get a single account
      operationId: getAccount
      parameters:
        - name: account_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: Account details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Account"
  /api/v1/courses:
    get:
      summary: List courses
      operationId: listCourses
      responses:
        "200":
          description: A paginated list of courses
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Course"
  /api/v1/courses/{course_id}:
    get:
      summary: Get a single course
      operationId: getCourse
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: Course details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Course"
  /api/v1/courses/{course_id}/assignments:
    get:
      summary: List assignments
      operationId: listAssignments
      parameters:


key: _node_content
string_value:
{"id_": "c80a784a-f11c-4303-bc0d-97ff6bfc71f2", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "814bcd65-485f-440e-a36a-6452fbc67cdf", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "5d9fc69b32c5c60bc934cea2c4d4dc439c559f48db2d7958eeb188136d38e93d", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "a318bb57-b545-44ba-915f-4187bb22a777", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "1b9b03055939690c3227e45a1b76c509fb44d89b508a1e3dd26c0bc230c97cbf", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "0f97fdd2-4d8b-4d8e-b6ab-7477304b57c5", "node_type": "1", "metadata": {}, "hash": "b3c2541a0ef9224c7da301064ff21ea8ff287ea5a7ea1137202392841ee4fd08", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 4364, "end_char_idx": 5927, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
responses:
        "200":
          description: A paginated list of courses
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Course"
  /api/v1/courses/{course_id}:
    get:
      summary: Get a single course
      operationId: getCourse
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: Course details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Course"
  /api/v1/courses/{course_id}/assignments:
    get:
      summary: List assignments
      operationId: listAssignments
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: A paginated list of assignments
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Assignment"
  /api/v1/courses/{course_id}/assignments/{assignment_id}:
    get:
      summary: Get a single assignment
      operationId: getAssignment
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
        - name: assignment_id
          in: path
          required: true
          schema:


key: _node_content
string_value:
{"id_": "0f97fdd2-4d8b-4d8e-b6ab-7477304b57c5", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "814bcd65-485f-440e-a36a-6452fbc67cdf", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "5d9fc69b32c5c60bc934cea2c4d4dc439c559f48db2d7958eeb188136d38e93d", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "c80a784a-f11c-4303-bc0d-97ff6bfc71f2", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "1f6ed488d460c9d5b56f74225c02694f3bcc034150cff4b75ed6ff5895352bbe", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "82565b75-1397-48db-899a-88ad787e5369", "node_type": "1", "metadata": {}, "hash": "790eac1f0947e78ac163e910bfcfb0b6fdac4cee2bed9c05def4ec8dd03b0adc", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 5104, "end_char_idx": 6650, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
summary: List assignments
      operationId: listAssignments
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: A paginated list of assignments
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Assignment"
  /api/v1/courses/{course_id}/assignments/{assignment_id}:
    get:
      summary: Get a single assignment
      operationId: getAssignment
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
        - name: assignment_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: Assignment details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Assignment"
  /api/v1/courses/{course_id}/quizzes:
    get:
      summary: List quizzes
      operationId: listQuizzes
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: A paginated list of quizzes
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Quiz"


key: _node_content
string_value:
{"id_": "82565b75-1397-48db-899a-88ad787e5369", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "814bcd65-485f-440e-a36a-6452fbc67cdf", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "5d9fc69b32c5c60bc934cea2c4d4dc439c559f48db2d7958eeb188136d38e93d", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "0f97fdd2-4d8b-4d8e-b6ab-7477304b57c5", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "b2a4d4914819ee4c410fcbe0b94827567276be0e7b53c5c54358a9da41119d2c", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "0fc98141-560a-4bda-9bee-695a4e656250", "node_type": "1", "metadata": {}, "hash": "5f18597081ca8b34e0a30d0e79295c780a2603cc6f593e8f2d3fa23ed65d217b", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 5876, "end_char_idx": 7410, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: Assignment details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Assignment"
  /api/v1/courses/{course_id}/quizzes:
    get:
      summary: List quizzes
      operationId: listQuizzes
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: A paginated list of quizzes
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Quiz"
  /api/v1/courses/{course_id}/quizzes/{quiz_id}:
    get:
      summary: Get a single quiz
      operationId: getQuiz
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
        - name: quiz_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: Quiz details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Quiz"
  /api/v1/courses/{course_id}/students/{student_id}/grades:
     get:
       summary: List grades for a student
       operationId: listGrades
       parameters:
         - name: course_id
           in: path


key: _node_content
string_value:
{"id_": "0fc98141-560a-4bda-9bee-695a4e656250", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "814bcd65-485f-440e-a36a-6452fbc67cdf", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "5d9fc69b32c5c60bc934cea2c4d4dc439c559f48db2d7958eeb188136d38e93d", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "82565b75-1397-48db-899a-88ad787e5369", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "ba58571d60ea202b217d6602afbbd2933c7e04470d11f4956761060f8452cb28", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "70a383da-0ad0-4bcd-9e4c-673f0d77c547", "node_type": "1", "metadata": {}, "hash": "c42e6bf7ec31646ea9b259c219f63ba525fbf4c7b208ed16c9f46010d34b7b01", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 6592, "end_char_idx": 8122, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
items:
                  $ref: "#/components/schemas/Quiz"
  /api/v1/courses/{course_id}/quizzes/{quiz_id}:
    get:
      summary: Get a single quiz
      operationId: getQuiz
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
        - name: quiz_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: Quiz details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Quiz"
  /api/v1/courses/{course_id}/students/{student_id}/grades:
     get:
       summary: List grades for a student
       operationId: listGrades
       parameters:
         - name: course_id
           in: path
           required: true
           schema:
             type: integer
         - name: student_id
           in: path
           required: true
           schema:
             type: integer
       responses:
         '200':
           description: A list of grades for the student
           content:
             application/json:
               schema:
                 type: array
                 items:
                   $ref: '#/components/schemas/Grade'
  /api/v1/courses/{course_id}/students/{student_id}/grades/{grade_id}:
    get:
      summary: Get a single grade
      operationId: getGrade
      parameters:
        - name: course_id
          in: path
          required: true
          schema:


key: _node_content
string_value:
{"id_": "70a383da-0ad0-4bcd-9e4c-673f0d77c547", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "814bcd65-485f-440e-a36a-6452fbc67cdf", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "5d9fc69b32c5c60bc934cea2c4d4dc439c559f48db2d7958eeb188136d38e93d", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "0fc98141-560a-4bda-9bee-695a4e656250", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "4924bd95605529ee4731d9d916023dd3f867cf7ee4c8e4ca6126092c4068c56f", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "7c1ca7fd-234f-4ba8-b4ba-baf7dddb429b", "node_type": "1", "metadata": {}, "hash": "2f2dc3497a52a52e7e50ee32a030a4812df06ee8b5c284fa76a73dbe45f18401", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 7352, "end_char_idx": 8831, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
parameters:
         - name: course_id
           in: path
           required: true
           schema:
             type: integer
         - name: student_id
           in: path
           required: true
           schema:
             type: integer
       responses:
         '200':
           description: A list of grades for the student
           content:
             application/json:
               schema:
                 type: array
                 items:
                   $ref: '#/components/schemas/Grade'
  /api/v1/courses/{course_id}/students/{student_id}/grades/{grade_id}:
    get:
      summary: Get a single grade
      operationId: getGrade
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
        - name: student_id
          in: path
          required: true
          schema:
            type: integer
        - name: grade_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Grade details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Grade'
  /api/v1/courses/{course_id}/syllabus:
    get:
      summary: Get course syllabus
      operationId: getSyllabus
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
      responses:


key: _node_content
string_value:
{"id_": "7c1ca7fd-234f-4ba8-b4ba-baf7dddb429b", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "814bcd65-485f-440e-a36a-6452fbc67cdf", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "5d9fc69b32c5c60bc934cea2c4d4dc439c559f48db2d7958eeb188136d38e93d", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "70a383da-0ad0-4bcd-9e4c-673f0d77c547", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "a760aa3b9d59fb35bfe0a73d6592a5f9214f5e0fed3fc9259af7db4a86812e48", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "26b5f918-eae2-4f48-95e7-4da9b896897a", "node_type": "1", "metadata": {}, "hash": "561056e86e60a6c03b05bba153f73c7d09d4420a9391f0470f17d4aaac50c65e", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 8071, "end_char_idx": 9588, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
in: path
          required: true
          schema:
            type: integer
        - name: student_id
          in: path
          required: true
          schema:
            type: integer
        - name: grade_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Grade details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Grade'
  /api/v1/courses/{course_id}/syllabus:
    get:
      summary: Get course syllabus
      operationId: getSyllabus
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Syllabus details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Syllabus'
  /api/v1/courses/{course_id}/modules:
    get:
      summary: List modules
      operationId: listModules
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: A list of modules in the course
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Module'
  /api/v1/courses/{course_id}/modules/{module_id}:
    get:
      summary:


key: _node_content
string_value:
{"id_": "26b5f918-eae2-4f48-95e7-4da9b896897a", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "814bcd65-485f-440e-a36a-6452fbc67cdf", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "5d9fc69b32c5c60bc934cea2c4d4dc439c559f48db2d7958eeb188136d38e93d", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "7c1ca7fd-234f-4ba8-b4ba-baf7dddb429b", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "e88ca48502fddfdb90cb45e38f82a9a541ef329735c89e3402713f676c99869d", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "5e1b0946-23ef-4bf3-beb1-362e370cab4a", "node_type": "1", "metadata": {}, "hash": "f2bb1445c10a451995847b2ccdededf8b2f175ef358a10d3b69ba52d6287118f", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 8781, "end_char_idx": 10318, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
schema:
            type: integer
      responses:
        '200':
          description: Syllabus details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Syllabus'
  /api/v1/courses/{course_id}/modules:
    get:
      summary: List modules
      operationId: listModules
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: A list of modules in the course
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Module'
  /api/v1/courses/{course_id}/modules/{module_id}:
    get:
      summary: Get a single module
      operationId: getModule
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
        - name: module_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Module details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Module'
components:
  schemas:
    Account:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        workflow_state:
          type: string
    Course:
      type: object
      properties:


key: _node_content
string_value:
{"id_": "5e1b0946-23ef-4bf3-beb1-362e370cab4a", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "814bcd65-485f-440e-a36a-6452fbc67cdf", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "5d9fc69b32c5c60bc934cea2c4d4dc439c559f48db2d7958eeb188136d38e93d", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "26b5f918-eae2-4f48-95e7-4da9b896897a", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "6742873f686e4c7328fa51a282a9d942c8280f6162c50a4a5a9830d64002d2c6", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "d83e9d28-8a88-4e8f-8467-26ddad4d4c61", "node_type": "1", "metadata": {}, "hash": "b132c387a92272479eab6c7f1c75eb108e93eb746b43fefc7bf16d26788f38b3", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 9516, "end_char_idx": 11021, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
/api/v1/courses/{course_id}/modules/{module_id}:
    get:
      summary: Get a single module
      operationId: getModule
      parameters:
        - name: course_id
          in: path
          required: true
          schema:
            type: integer
        - name: module_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Module details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Module'
components:
  schemas:
    Account:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        workflow_state:
          type: string
    Course:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        account_id:
          type: integer
        start_at:
          type: string
          format: date-time
        end_at:
          type: string
          format: date-time
    Assignment:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        description:
          type: string
        due_at:
          type: string
          format: date-time
        points_possible:
          type: number
    Quiz:
      type: object
      properties:
        id:
          type: integer
        title:
          type: string
        description:
          type: string


key: _node_content
string_value:
{"id_": "d83e9d28-8a88-4e8f-8467-26ddad4d4c61", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "814bcd65-485f-440e-a36a-6452fbc67cdf", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "5d9fc69b32c5c60bc934cea2c4d4dc439c559f48db2d7958eeb188136d38e93d", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "5e1b0946-23ef-4bf3-beb1-362e370cab4a", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "1e0597b48dcfb9f0459c1baeee4de8c6202e0b9bf23bbaec9ec529e898c48015", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "b095c491-6a7b-4adf-98e4-4da7f4c3a63e", "node_type": "1", "metadata": {}, "hash": "9649608b95afbb434245406dc0aead34f2a4919f0932d85f31b52e772309efe0", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 10257, "end_char_idx": 11706, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
type: string
    Course:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        account_id:
          type: integer
        start_at:
          type: string
          format: date-time
        end_at:
          type: string
          format: date-time
    Assignment:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        description:
          type: string
        due_at:
          type: string
          format: date-time
        points_possible:
          type: number
    Quiz:
      type: object
      properties:
        id:
          type: integer
        title:
          type: string
        description:
          type: string
        due_at:
          type: string
          format: date-time
        points_possible:
          type: number
    Grade:
      type: object
      properties:
        id:
          type: integer
        student_id:
          type: integer
        course_id:
          type: integer
        assignment_id:
          type: integer
        score:
          type: number
        grade:
          type: string
    Syllabus:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        account_id:
          type: integer
        start_at:
          type: string
          format: date-time
        end_at:
          type: string


key: _node_content
string_value:
{"id_": "b095c491-6a7b-4adf-98e4-4da7f4c3a63e", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "814bcd65-485f-440e-a36a-6452fbc67cdf", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "5d9fc69b32c5c60bc934cea2c4d4dc439c559f48db2d7958eeb188136d38e93d", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "d83e9d28-8a88-4e8f-8467-26ddad4d4c61", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "e1abefc4db39c1c782cdb491923bdf43075e4ddca32e243f294f51b58946c978", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "590896c2-ece1-4301-8e00-cf5dd2b33aee", "node_type": "1", "metadata": {}, "hash": "a77bb54a3415cc72a6dd24888762b5e467f066b99f5327e7671df294d6cd2d03", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 10965, "end_char_idx": 12754, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
type: string
        description:
          type: string
        due_at:
          type: string
          format: date-time
        points_possible:
          type: number
    Grade:
      type: object
      properties:
        id:
          type: integer
        student_id:
          type: integer
        course_id:
          type: integer
        assignment_id:
          type: integer
        score:
          type: number
        grade:
          type: string
    Syllabus:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        account_id:
          type: integer
        start_at:
          type: string
          format: date-time
        end_at:
          type: string
          format: date-time
        syllabus_body:
          type: string
        syllabus_url:
          type: string
    Module:
     type: object
     properties:
       id:
         type: integer
       name:
         type: string
       position:
         type: integer
       unlock_at:
         type: string
         format: date-time
       require_sequential_progress:
         type: boolean
       state:
         type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
security:
  - bearerAuth: []
```

**Note : this schema above does not contain all possible API endpoints, be sure to edit the schema to produce the appropriate actions from canvas [API documentation](https://canvas.instructure.com/doc/api/)**

## Authentication Instructions

Below are instructions on setting up authentication with this 3rd party application. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.


key: _node_content
string_value:
{"id_": "590896c2-ece1-4301-8e00-cf5dd2b33aee", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "814bcd65-485f-440e-a36a-6452fbc67cdf", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "5d9fc69b32c5c60bc934cea2c4d4dc439c559f48db2d7958eeb188136d38e93d", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "b095c491-6a7b-4adf-98e4-4da7f4c3a63e", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "52a29616fa233fac12af40038d22530bc1ccd7eb96e3d753d07375ed69ed2f42", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "02fceea1-a3f1-4681-9ed2-bca7849b5a26", "node_type": "1", "metadata": {}, "hash": "982d739678175bf3b3244fa608fced3f3b7ecd5bb022e9753f1a07380dc0c44a", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 11650, "end_char_idx": 14058, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
format: date-time
        end_at:
          type: string
          format: date-time
        syllabus_body:
          type: string
        syllabus_url:
          type: string
    Module:
     type: object
     properties:
       id:
         type: integer
       name:
         type: string
       position:
         type: integer
       unlock_at:
         type: string
         format: date-time
       require_sequential_progress:
         type: boolean
       state:
         type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
security:
  - bearerAuth: []
```

**Note : this schema above does not contain all possible API endpoints, be sure to edit the schema to produce the appropriate actions from canvas [API documentation](https://canvas.instructure.com/doc/api/)**

## Authentication Instructions

Below are instructions on setting up authentication with this 3rd party application. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.

### Pre-Action Steps

Before you set up authentication in ChatGPT, please take the following steps in the application. Our sample integration below is utilizing a secret key, which is an easier method for testing. In production, it is more common to establish an OAuth connection to ensure permissions are respected from ChatGPT to Canvas, ensuring users the appropriate access. 

1. Canvas accounts : The first step is to ensure the canvas environment has users assigned to the appropriate role (student / teacher) with any access to appropriate courses
2. For testing purposes or service level account access create an approved integration access token as seen below
- Under Account -> Settings -> Approved Integrations

<br> ![gptactions_canvaslms_settings.png](../../../images/gptactions_canvaslms_settings.png)

- Create new Access Token

<br> ![gptactions_canvaslms_integrationslist.png](../../../images/gptactions_canvaslms_integrationslist.png)

- Provide purpose and expiration

<br> ![gptactions_canvaslms_tokencreate.png](../../../images/gptactions_canvaslms_tokencreate.png)

- Copy the new Token to use in the GPT Action (the token will not be accessible once you leave the page - ensure proper token management access is maintained to prevent unauthorzied access from another application.


key: _node_content
string_value:
{"id_": "02fceea1-a3f1-4681-9ed2-bca7849b5a26", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "814bcd65-485f-440e-a36a-6452fbc67cdf", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "5d9fc69b32c5c60bc934cea2c4d4dc439c559f48db2d7958eeb188136d38e93d", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "590896c2-ece1-4301-8e00-cf5dd2b33aee", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_canvaslms.ipynb", "title": "GPT Action Library: Canvas LMS", "tokens": 3423, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "8c3d37dfa47fdae344ac3a8f5b974c2bc2c291ad381a1076d98070a8eedfefa4", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 12202, "end_char_idx": 16078, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
scheme: bearer
      bearerFormat: JWT
security:
  - bearerAuth: []
```

**Note : this schema above does not contain all possible API endpoints, be sure to edit the schema to produce the appropriate actions from canvas [API documentation](https://canvas.instructure.com/doc/api/)**

## Authentication Instructions

Below are instructions on setting up authentication with this 3rd party application. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.

### Pre-Action Steps

Before you set up authentication in ChatGPT, please take the following steps in the application. Our sample integration below is utilizing a secret key, which is an easier method for testing. In production, it is more common to establish an OAuth connection to ensure permissions are respected from ChatGPT to Canvas, ensuring users the appropriate access. 

1. Canvas accounts : The first step is to ensure the canvas environment has users assigned to the appropriate role (student / teacher) with any access to appropriate courses
2. For testing purposes or service level account access create an approved integration access token as seen below
- Under Account -> Settings -> Approved Integrations

<br> ![gptactions_canvaslms_settings.png](../../../images/gptactions_canvaslms_settings.png)

- Create new Access Token

<br> ![gptactions_canvaslms_integrationslist.png](../../../images/gptactions_canvaslms_integrationslist.png)

- Provide purpose and expiration

<br> ![gptactions_canvaslms_tokencreate.png](../../../images/gptactions_canvaslms_tokencreate.png)

- Copy the new Token to use in the GPT Action (the token will not be accessible once you leave the page - ensure proper token management access is maintained to prevent unauthorzied access from another application.


### In ChatGPT

In ChatGPT, click on "Authentication" and choose **"API Key"**. Enter in the information below. API Key provides general access to the Canvas environment based on the users permissions that created the API key, to follow permission models in Canvas use the OAuth method described below.

- **API Key**: Use the token from above 
- **Auth Type**: Bearer

<br> ![gptactions_canvaslms_auth.png](../../../images/gptactions_canvaslms_auth.png)

**OAuth Connection**

If you want to implement OAuth, follow the guide here : https://canvas.instructure.com/doc/api/file.oauth.html - specific instructions can vary depending on the Canvas implementation.

Parameters for GPT Configuration
- Client ID - obtained from site owner
- Client Secret - obtained from site owner 
- Authorization URL - : https://< canvas-install-url >/login/oauth2/auth?client_id=XXX&response_type=code&redirect_uri=https://example.com/oauth_complete&state=YYY&scope=< value_1 >%20< value_2 >%20< value_n >
- Token URL : https://< canvas-install-url> /login/oauth2/token 

### Post-Action Steps

Once you've set up authentication in ChatGPT, follow the steps below in the application to test the Action.

- You will see a list of available actions from the API schema for Canvas, you can test the endpoints from the GPT builder to ensure Canvas can be reached. Once you verified connection make sure to save the GPT and share it witht the appropriate user base.
- Note: if you are using OAuth, you will need to set up the callback URL from ChatGPT in the Canvas app

### FAQ & Troubleshooting

- *Schema calls the wrong project or dataset:* If ChatGPT calls the wrong project or dataset, consider updating your instructions to make it more explicit either (a) which project / dataset should be called or (b) to require the user provide those exact details before it runs the query

*Are there integrations that you’d like us to prioritize? Are there errors in our integrations? File a PR or issue in our github, and we’ll take a look.*


key: url
string_value:
https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb


key: _node_content
string_value:
{"id_": "4a842ca9-1544-4c6a-903e-eb1559d4d833", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "5d0d9b15-9906-415c-b05f-7e453ab81646", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "44d7328e4b5dce8556b9ba5a13491cc0c5403634e0e06500d6162de7f3cc9f20", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "23e20364-66e2-4305-a6eb-5d5d0eb201a5", "node_type": "1", "metadata": {}, "hash": "9608d55c1f2b80d30ebe7365dc5c7671ef9154d3ef96c80bef4755b36e919a24", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 0, "end_char_idx": 3151, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
# GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)

## Introduction

This page provides an instruction & guide for developers building a GPT Action for a specific application. Before you proceed, make sure to first familiarize yourself with the following information: 
- [Introduction to GPT Actions](https://platform.openai.com/docs/actions)
- [Introduction to GPT Actions Library](https://platform.openai.com/docs/actions/actions-library)
- [Example of Building a GPT Action from Scratch](https://platform.openai.com/docs/actions/getting-started)

This solution enables a GPT action to answer a user’s question with the context of files the user can access in SharePoint or Office365, using Microsoft’s Graph API [search capabilities](https://learn.microsoft.com/en-us/graph/api/resources/search-api-overview?view=graph-rest-1.0) and the ability to [retrieve files](https://learn.microsoft.com/en-us/graph/api/driveitem-get?view=graph-rest-1.0\&tabs=http). It uses Azure Functions to process the Graph API response and convert it to a human readable format or structure it in a way ChatGPT understands. This code is meant to be directional, and you should modify it to your requirements.

This solution uses the ability to[ retrieve files in Actions](https://platform.openai.com/docs/actions/sending-files) and use them as if you had uploaded them directly to a conversation. The Azure Function returns a base64 string that ChatGPT converts into a file. This solution can handle both structured and unstructured data, but does have size volume limitations (see docs [here](https://platform.openai.com/docs/actions/sending-files))

### Value + Example Business Use Cases

**Value**: Users can now leverage ChatGPT's natural language capability to connect directly to files in Sharpeoint

**Example Use Cases**: 
- A user needs to look up which files relate to a certain topic
- A user needs an answer to a critical question, buried deep in documents

## Architecture / Example

![](../../../images/solution_1.gif)


This solution uses a Node.js Azure Function to, based on the logged in user:

1. Search for a relevant file that the user has access to, based on the user’s initial question. 

2. For each file that is found, convert it to a base64 string.

3. Format the data in the structure ChatGPT is expecting [here](https://platform.openai.com/docs/actions/sending-files/inline-option).

4. Return that to ChatGPT. The GPT then can use those files as if you had uploaded it to the conversation.

![](../../../images/solution_1_architecture.png)

## Application Information

### Application Key Links

Check out these links from the application before you get started:
- Application Website: https://www.microsoft.com/en-us/microsoft-365/sharepoint/collaboration
- Application API Documentation: https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-rest-reference/

### Application Prerequisites

Before you get started, make sure you go through the following steps in your application environment:
- Access to a Sharepoint environment 
- Postman (and knowledge of APIs and OAuth)


key: _node_content
string_value:
{"id_": "23e20364-66e2-4305-a6eb-5d5d0eb201a5", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "5d0d9b15-9906-415c-b05f-7e453ab81646", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "44d7328e4b5dce8556b9ba5a13491cc0c5403634e0e06500d6162de7f3cc9f20", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "4a842ca9-1544-4c6a-903e-eb1559d4d833", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "11b6c96af5a58077e72af8ea1e860949b5c1f0cd9e3361319b4ad277fece3e3c", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "3719e88c-65f6-47ed-b645-ad23b9ae8c0b", "node_type": "1", "metadata": {}, "hash": "34da1156f1121dfd44962762f258e9bbd4c662859a2c3abe2f2e88a259e51727", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 2056, "end_char_idx": 5474, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
This solution uses a Node.js Azure Function to, based on the logged in user:

1. Search for a relevant file that the user has access to, based on the user’s initial question. 

2. For each file that is found, convert it to a base64 string.

3. Format the data in the structure ChatGPT is expecting [here](https://platform.openai.com/docs/actions/sending-files/inline-option).

4. Return that to ChatGPT. The GPT then can use those files as if you had uploaded it to the conversation.

![](../../../images/solution_1_architecture.png)

## Application Information

### Application Key Links

Check out these links from the application before you get started:
- Application Website: https://www.microsoft.com/en-us/microsoft-365/sharepoint/collaboration
- Application API Documentation: https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-rest-reference/

### Application Prerequisites

Before you get started, make sure you go through the following steps in your application environment:
- Access to a Sharepoint environment 
- Postman (and knowledge of APIs and OAuth)


## Middleware Information

If you follow the [search concept files guide](https://learn.microsoft.com/en-us/graph/search-concept-files), the [Microsoft Graph Search API](https://learn.microsoft.com/en-us/graph/search-concept-files) returns references to files that fit the criteria, but not the file contents themselves. Therefore, middleware is required, rather than hitting the MSFT endpoints directly.

We need to restructure the response from that API so that it matches the expected structure in `openaiFileResponse` outlined [here](https://platform.openai.com/docs/actions/getting-started/inline-option).

### Additional Steps

#### Set up Azure Function

1. Set up an Azure Function using the steps in the [Azure Function cookbook](https://cookbook.openai.com/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function)

#### Add in Function Code

Now that you have an authenticated Azure Function, we can update the function to search SharePoint / O365

2. Go to your test function and paste in the code from [this file](https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/sharepoint_azure_function/solution_one_file_retrieval.js). Save the function.

> **This code is meant to be directional** - while it should work out of the box, it is designed to be customized to your needs (see examples towards the end of this document).

3. Set up the following env variables by going to the **Configuration** tab on the left under **Settings.** Note that this may be listed directly in **Environment Variables** depending on your Azure UI.

    1. `TENANT_ID`: copied from previous section

    2. `CLIENT_ID`: copied from previous section

4. Go to the **Console** tab under the **Development Tools**

    1. Install the following packages in console

       1. `npm install @microsoft/microsoft-graph-client`

       2. `npm install axios`

5. Once this is complete, try calling the function (POST call) from Postman again, putting the below into body (using a query and search term you think will generate responses).

     ```json
    {
        "searchTerm": "<choose a search term>"
    }
    ```

6. If you get a response, you are ready to set this up with a Custom GPT! See the ChatGPT Section of the Azure Function page for more details on setting this up


## More Detailed Walkthrough


key: _node_content
string_value:
{"id_": "3719e88c-65f6-47ed-b645-ad23b9ae8c0b", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "5d0d9b15-9906-415c-b05f-7e453ab81646", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "44d7328e4b5dce8556b9ba5a13491cc0c5403634e0e06500d6162de7f3cc9f20", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "23e20364-66e2-4305-a6eb-5d5d0eb201a5", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "f6044fe73cbf6bc4160282038fa3b1189e858d1e80a6c52f07756d1c1450eead", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "acf882c4-e06b-4206-9f06-27ef61006d16", "node_type": "1", "metadata": {}, "hash": "98227c9a5ba660ee865051b4ae2f8386c509d94287b093f95cdacb8180c472e0", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 5446, "end_char_idx": 7934, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
## More Detailed Walkthrough


The below walks through setup instructions and walkthrough unique to this solution. You can find the entire code [here](https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/sharepoint_azure_function/solution_one_file_retrieval.js).

### Code Walkthrough

The below walks through the different parts of the function. Before you begin, ensure you have the required packages installed and environment variables set up (see the Installation Steps section).


#### Implementing the Authentication 

Below we have a few helper functions that we’ll use in the function.


##### Initializing the Microsoft Graph Client

Create a function to initialize the Graph client with an access token. This will be used to search through Office 365 and SharePoint.

```javascript
const { Client } = require('@microsoft/microsoft-graph-client');

function initGraphClient(accessToken) {
    return Client.init({
        authProvider: (done) => {
            done(null, accessToken);
        }
    });
}
```

##### Obtaining an On-Behalf-Of (OBO) Token

This function uses an existing bearer token to request an OBO token from Microsoft's identity platform. This enables passing through the credentials to ensure the search only returns files the logged-in user can access.

```javascript
const axios = require('axios');
const qs = require('querystring');

async function getOboToken(userAccessToken) {
    const { TENANT_ID, CLIENT_ID, MICROSOFT_PROVIDER_AUTHENTICATION_SECRET } = process.env;
    const params = {
        client_id: CLIENT_ID,
        client_secret: MICROSOFT_PROVIDER_AUTHENTICATION_SECRET,
        grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
        assertion: userAccessToken,
        requested_token_use: 'on_behalf_of',
        scope: 'https://graph.microsoft.com/.default'
    };

    const url = `https\://login.microsoftonline.com/${TENANT_ID}/oauth2/v2.0/token`;
    try {
        const response = await axios.post(url, qs.stringify(params), {
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        });
        return response.data.access\_token;
    } catch (error) {
        console.error('Error obtaining OBO token:', error.response?.data || error.message);
        throw error;
    }
}
```

#### Retrieving Content from O365 / SharePoint Items

This function fetches the content of drive items, converts it to a base64 string, and restructures to match the `openaiFileResponse` format.


key: _node_content
string_value:
{"id_": "acf882c4-e06b-4206-9f06-27ef61006d16", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "5d0d9b15-9906-415c-b05f-7e453ab81646", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "44d7328e4b5dce8556b9ba5a13491cc0c5403634e0e06500d6162de7f3cc9f20", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "3719e88c-65f6-47ed-b645-ad23b9ae8c0b", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "f82efdec559fb9467d9c44926942d0f462aaf67983ecddc7b012e428c89797fb", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "86305e1d-0f95-4811-a718-11243be49367", "node_type": "1", "metadata": {}, "hash": "4938b5c03c6fa5a7a2c2b52ae6043e6e7fc2daf7327352fc674fde37ce3deabc", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 6240, "end_char_idx": 9420, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
```javascript
const { Client } = require('@microsoft/microsoft-graph-client');

function initGraphClient(accessToken) {
    return Client.init({
        authProvider: (done) => {
            done(null, accessToken);
        }
    });
}
```

##### Obtaining an On-Behalf-Of (OBO) Token

This function uses an existing bearer token to request an OBO token from Microsoft's identity platform. This enables passing through the credentials to ensure the search only returns files the logged-in user can access.

```javascript
const axios = require('axios');
const qs = require('querystring');

async function getOboToken(userAccessToken) {
    const { TENANT_ID, CLIENT_ID, MICROSOFT_PROVIDER_AUTHENTICATION_SECRET } = process.env;
    const params = {
        client_id: CLIENT_ID,
        client_secret: MICROSOFT_PROVIDER_AUTHENTICATION_SECRET,
        grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
        assertion: userAccessToken,
        requested_token_use: 'on_behalf_of',
        scope: 'https://graph.microsoft.com/.default'
    };

    const url = `https\://login.microsoftonline.com/${TENANT_ID}/oauth2/v2.0/token`;
    try {
        const response = await axios.post(url, qs.stringify(params), {
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        });
        return response.data.access\_token;
    } catch (error) {
        console.error('Error obtaining OBO token:', error.response?.data || error.message);
        throw error;
    }
}
```

#### Retrieving Content from O365 / SharePoint Items

This function fetches the content of drive items, converts it to a base64 string, and restructures to match the `openaiFileResponse` format.
```javascript
const getDriveItemContent = async (client, driveId, itemId, name) => {
   try
       const filePath = `/drives/${driveId}/items/${itemId}`;
       const downloadPath = filePath + `/content`
       // this is where we get the contents and convert to base64
       const fileStream = await client.api(downloadPath).getStream();
       let chunks = [];
           for await (let chunk of fileStream) {
               chunks.push(chunk);
           }
       const base64String = Buffer.concat(chunks).toString('base64');
       // this is where we get the other metadata to include in response
       const file = await client.api(filePath).get();
       const mime_type = file.file.mimeType;
       const name = file.name;
       return {"name":name, "mime_type":mime_type, "content":base64String}
   } catch (error) {
       console.error('Error fetching drive content:', error);
       throw new Error(`Failed to fetch content for ${name}: ${error.message}`);
   }
```

#### Creating the Azure Function to Handle Requests

Now that we have all these helper functions, the Azure Function will orchestrate the flow, by authenticating the user, performing the search, and iterating through the search results to extract the text and retrieve the relevant parts of the text to the GPT.

**Handling HTTP Requests:** The function starts by extracting the query and searchTerm from the HTTP request. It checks if the Authorization header is present and extracts the bearer token.


key: _node_content
string_value:
{"id_": "86305e1d-0f95-4811-a718-11243be49367", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "5d0d9b15-9906-415c-b05f-7e453ab81646", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "44d7328e4b5dce8556b9ba5a13491cc0c5403634e0e06500d6162de7f3cc9f20", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "acf882c4-e06b-4206-9f06-27ef61006d16", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "a465afd983581991f057bb5bbcf8e257f9891486ccbc58bb8061432724f14130", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "4fb5fe75-df33-4e55-9e4a-5d0eca7ce4a5", "node_type": "1", "metadata": {}, "hash": "7db814d396dcc8e6ee55df676c6bb3bd6db91b0492137bfde266e988f624d8bb", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 7935, "end_char_idx": 10597, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
```javascript
const getDriveItemContent = async (client, driveId, itemId, name) => {
   try
       const filePath = `/drives/${driveId}/items/${itemId}`;
       const downloadPath = filePath + `/content`
       // this is where we get the contents and convert to base64
       const fileStream = await client.api(downloadPath).getStream();
       let chunks = [];
           for await (let chunk of fileStream) {
               chunks.push(chunk);
           }
       const base64String = Buffer.concat(chunks).toString('base64');
       // this is where we get the other metadata to include in response
       const file = await client.api(filePath).get();
       const mime_type = file.file.mimeType;
       const name = file.name;
       return {"name":name, "mime_type":mime_type, "content":base64String}
   } catch (error) {
       console.error('Error fetching drive content:', error);
       throw new Error(`Failed to fetch content for ${name}: ${error.message}`);
   }
```

#### Creating the Azure Function to Handle Requests

Now that we have all these helper functions, the Azure Function will orchestrate the flow, by authenticating the user, performing the search, and iterating through the search results to extract the text and retrieve the relevant parts of the text to the GPT.

**Handling HTTP Requests:** The function starts by extracting the query and searchTerm from the HTTP request. It checks if the Authorization header is present and extracts the bearer token.

**Authentication:** Using the bearer token, it obtains an OBO token from Microsoft's identity platform using getOboToken defined above.

**Initializing the Graph Client:** With the OBO token, it initializes the Microsoft Graph client using initGraphClient defined above.

**Document Search:** It constructs a search query and sends it to the Microsoft Graph API to find documents based on the searchTerm.

**Document Processing**: For each document returned by the search:

- It retrieves the document content using getDriveItemContent.

- It converts the document to base64 string and restructures it to match the `openaiFileResponse` structure.

**Response**: The function sends them back in the HTTP response.
```javascript
module.exports = async function (context, req) {
   // const query = req.query.query || (req.body && req.body.query);
   const searchTerm = req.query.searchTerm || (req.body && req.body.searchTerm);
   if (!req.headers.authorization) {
       context.res = {
           status: 400,
           body: 'Authorization header is missing'
       };
       return;
   }
   /// The below takes the token passed to the function, to use to get an OBO token.


key: _node_content
string_value:
{"id_": "4fb5fe75-df33-4e55-9e4a-5d0eca7ce4a5", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "5d0d9b15-9906-415c-b05f-7e453ab81646", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "44d7328e4b5dce8556b9ba5a13491cc0c5403634e0e06500d6162de7f3cc9f20", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "86305e1d-0f95-4811-a718-11243be49367", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "1146db340ffb799d6ea5139bbc43707e228ac9d080ba851b216bad10f6e7344c", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "a3280e97-c6e1-42ea-92d6-39eab4bfb5b7", "node_type": "1", "metadata": {}, "hash": "33d7e4d8119d1ad5d98e5b33283c58f314f50b8bab21a98a4d791cb812724687", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 9231, "end_char_idx": 11568, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: _node_content
string_value:
{"id_": "a3280e97-c6e1-42ea-92d6-39eab4bfb5b7", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "5d0d9b15-9906-415c-b05f-7e453ab81646", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "44d7328e4b5dce8556b9ba5a13491cc0c5403634e0e06500d6162de7f3cc9f20", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "4fb5fe75-df33-4e55-9e4a-5d0eca7ce4a5", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "27a4b0314a22444216322032223f48b34d1240b851918078bf300702442bd8ee", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "2e83003f-057b-462e-a5f4-3953c51d36f6", "node_type": "1", "metadata": {}, "hash": "d6bc1de29bb1b4e65039297ca5c50478d93fad34849cb001480d93da08a7db9f", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 9694, "end_char_idx": 14970, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
**Document Search:** It constructs a search query and sends it to the Microsoft Graph API to find documents based on the searchTerm.

**Document Processing**: For each document returned by the search:

- It retrieves the document content using getDriveItemContent.

- It converts the document to base64 string and restructures it to match the `openaiFileResponse` structure.

**Response**: The function sends them back in the HTTP response.
```javascript
module.exports = async function (context, req) {
   // const query = req.query.query || (req.body && req.body.query);
   const searchTerm = req.query.searchTerm || (req.body && req.body.searchTerm);
   if (!req.headers.authorization) {
       context.res = {
           status: 400,
           body: 'Authorization header is missing'
       };
       return;
   }
   /// The below takes the token passed to the function, to use to get an OBO token.
   const bearerToken = req.headers.authorization.split(' ')[1];
   let accessToken;
   try {
       accessToken = await getOboToken(bearerToken);
   } catch (error) {
       context.res = {
           status: 500,
           body: `Failed to obtain OBO token: ${error.message}`
       };
       return;
   }
   // Initialize the Graph Client using the initGraphClient function defined above
   let client = initGraphClient(accessToken);
   // this is the search body to be used in the Microsft Graph Search API: https://learn.microsoft.com/en-us/graph/search-concept-files
   const requestBody = {
       requests: [
           {
               entityTypes: ['driveItem'],
               query: {
                   queryString: searchTerm
               },
               from: 0,
               // the below is set to summarize the top 10 search results from the Graph API, but can configure based on your documents.
               size: 10
           }
       ]
   };


   try {
       // This is where we are doing the search
       const list = await client.api('/search/query').post(requestBody);
       const processList = async () => {
           // This will go through and for each search response, grab the contents of the file and summarize with gpt-3.5-turbo
           const results = [];
           await Promise.all(list.value[0].hitsContainers.map(async (container) => {
               for (const hit of container.hits) {
                   if (hit.resource["@odata.type"] === "#microsoft.graph.driveItem") {
                       const { name, id } = hit.resource;
                       // The below is where the file lives
                       const driveId = hit.resource.parentReference.driveId;
                       // we use the helper function we defined above to get the contents, convert to base64, and restructure it
                       const contents = await getDriveItemContent(client, driveId, id, name);
                       results.push(contents)
               }
           }));
           return results;
       };
       let results;
       if (list.value[0].hitsContainers[0].total == 0) {
           // Return no results found to the API if the Microsoft Graph API returns no results
           results = 'No results found';
       } else {
           // If the Microsoft Graph API does return results, then run processList to iterate through.
           results = await processList();
           // this is where we structure the response so ChatGPT knows they are files
           results = {'openaiFileResponse': results}
       }
       context.res = {
           status: 200,
           body: results
       };
   } catch (error) {
       context.res = {
           status: 500,
           body: `Error performing search or processing results: ${error.message}`,
       };
   }
};
```
### Customizations

Below are some potential areas to customize. 

- You can customize the GPT prompt to search again a certain amount of times if nothing is found.

- You can customize the code to only search through specific SharePoint sites or O365 Drives by customizing the search query. This will help focus the search and improve the retrieval. The function as setup now looks through all files the logged-in user can access.

- You can update the code to only return certain types of files. For example, only return structured data / CSVs. 

- You can customize the amount of files it searches through within the call to Microsoft Graph. Note that you should only put a maximum of 10 files based on the documentation [here](https://platform.openai.com/docs/actions/getting-started). 

### Considerations

Note that all the same limitations of Actions apply here, with regards to returning 100K characters or less and the [45 second timeout](https://platform.openai.com/docs/actions/production/timeouts).

- Make sure you read the documentation here around [returning files](https://platform.openai.com/docs/actions/sending-files) and [file uploads](https://help.openai.com/en/articles/8555545-file-uploads-faq), as those limitations apply here.

## ChatGPT Steps

### Custom GPT Instructions 

Once you've created a Custom GPT, copy the text below in the Instructions panel. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.


key: _node_content
string_value:
{"id_": "2e83003f-057b-462e-a5f4-3953c51d36f6", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "5d0d9b15-9906-415c-b05f-7e453ab81646", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "44d7328e4b5dce8556b9ba5a13491cc0c5403634e0e06500d6162de7f3cc9f20", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "a3280e97-c6e1-42ea-92d6-39eab4bfb5b7", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "5f90dc8e6e6778ed989f356dba8514c32d855e25e802cc8f0515a561ef55a127", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "a64134fa-af38-4614-aedf-faed2a9f6807", "node_type": "1", "metadata": {}, "hash": "239ad5ff878a9dde46688b3b0d0a27073511141f13099a810a28471167ce0fec", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 14973, "end_char_idx": 18814, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
```python
You are a Q&A helper that helps answer users questions. You have access to a documents repository through your API action. When a user asks a question, you pass in the "searchTerm" a single keyword or term you think you should use for the search.

****

Scenario 1: There are answers

If your action returns results, then you take the results from the action and try to answer the users question. 

****

Scenario 2: No results found

If the response you get from the action is "No results found", stop there and let the user know there were no results and that you are going to try a different search term, and explain why. You must always let the user know before conducting another search.

Example:

****

I found no results for "DEI". I am now going to try [insert term] because [insert explanation]

****

Then, try a different searchTerm that is similar to the one you tried before, with a single word. 

Try this three times. After the third time, then let the user know you did not find any relevant documents to answer the question, and to check SharePoint. 
Be sure to be explicit about what you are searching for at each step.

****

In either scenario, try to answer the user's question. If you cannot answer the user's question based on the knowledge you find, let the user know and ask them to go check the HR Docs in SharePoint. 
```

### OpenAPI Schema 

Once you've created a Custom GPT, copy the text below in the Actions panel. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.

This expects a response that matches the file retrieval structure in our doc [here](https://platform.openai.com/docs/actions/sending-files) and passes in a `searchTerm` parameter to inform the search.
>Make sure to switch the function app name, function name and code based on link copied in screenshot above


```python
openapi: 3.1.0
info:
  title: SharePoint Search API
  description: API for searching SharePoint documents.
  version: 1.0.0
servers:
  - url: https://{your_function_app_name}.azurewebsites.net/api
    description: SharePoint Search API server
paths:
  /{your_function_name}?code={enter your specific endpoint id here}:
    post:
      operationId: searchSharePoint
      summary: Searches SharePoint for documents matching a query and term.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                searchTerm:
                  type: string
                  description: A specific term to search for within the documents.
      responses:
        '200':
          description: A CSV file of query results encoded in base64.
          content:
            application/json:
              schema:
                type: object
                properties:
                  openaiFileResponseData:
                    type: array
                    items:
                      type: object
                      properties:
                        name:
                          type: string
                          description: The name of the file.
                        mime_type:
                          type: string
                          description: The MIME type of the file.
                        content:
                          type: string
                          format: byte
                          description: The base64 encoded contents of the file.
        '400':
          description: Bad request when the SQL query parameter is missing.
        '413':
          description: Payload too large if the response exceeds the size limit.
        '500':
          description: Server error when there are issues executing the query or encoding the results.


key: _node_content
string_value:
{"id_": "a64134fa-af38-4614-aedf-faed2a9f6807", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "5d0d9b15-9906-415c-b05f-7e453ab81646", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "44d7328e4b5dce8556b9ba5a13491cc0c5403634e0e06500d6162de7f3cc9f20", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "2e83003f-057b-462e-a5f4-3953c51d36f6", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "5e234e326775f0b4eb6ab673355c3596e6138b1d72973d3121ddd88d9097b096", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "75e29dab-3cc1-4bbe-9bc8-9b59ed619abb", "node_type": "1", "metadata": {}, "hash": "b13c8625b9d2d7684307167b38be391b31451b3645dcb08ae4cc7d001b551ee3", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 16896, "end_char_idx": 20548, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
```python
openapi: 3.1.0
info:
  title: SharePoint Search API
  description: API for searching SharePoint documents.
  version: 1.0.0
servers:
  - url: https://{your_function_app_name}.azurewebsites.net/api
    description: SharePoint Search API server
paths:
  /{your_function_name}?code={enter your specific endpoint id here}:
    post:
      operationId: searchSharePoint
      summary: Searches SharePoint for documents matching a query and term.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                searchTerm:
                  type: string
                  description: A specific term to search for within the documents.
      responses:
        '200':
          description: A CSV file of query results encoded in base64.
          content:
            application/json:
              schema:
                type: object
                properties:
                  openaiFileResponseData:
                    type: array
                    items:
                      type: object
                      properties:
                        name:
                          type: string
                          description: The name of the file.
                        mime_type:
                          type: string
                          description: The MIME type of the file.
                        content:
                          type: string
                          format: byte
                          description: The base64 encoded contents of the file.
        '400':
          description: Bad request when the SQL query parameter is missing.
        '413':
          description: Payload too large if the response exceeds the size limit.
        '500':
          description: Server error when there are issues executing the query or encoding the results.
```

## Authentication Instructions

Below are instructions on setting up authentication with this 3rd party application. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.

*See above and on the [Azure Function cookbook](https://cookbook.openai.com/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function) for more detailed instructions on authentication.*

## FAQ & Troubleshooting

- Why are you using the Microsoft Graph API in your code instead of the [SharePoint API](https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/get-to-know-the-sharepoint-rest-service?tabs=csom)?

  - The SharePoint API is legacy - per the Microsoft documentation [here](https://learn.microsoft.com/en-us/sharepoint/dev/apis/sharepoint-rest-graph), “For SharePoint Online, innovation using a REST API against SharePoint is driven via the Microsoft Graph REST API's.” The Graph API gives us more flexibility, and the SharePoint API still runs into the same file issues listed in the [Why is this necessary instead of interacting with the Microsoft Graph API directly?](#why-is-this-necessary-instead-of-interacting-with-the-microsoft-api-directly) section.

- What types of files does this support?

  It follows the same guidelines as the documentation [here](https://help.openai.com/en/articles/8555545-file-uploads-faq) about file uploads. 

- Why do I need to request an OBO token?

  - When you try to use the same token to authenticate to the Graph API as the one you use to authenticate into the Azure Function, you get an “invalid audience” token. This is because the audience for the token can only be user\_impersonation.


key: _node_content
string_value:
{"id_": "75e29dab-3cc1-4bbe-9bc8-9b59ed619abb", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "5d0d9b15-9906-415c-b05f-7e453ab81646", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "44d7328e4b5dce8556b9ba5a13491cc0c5403634e0e06500d6162de7f3cc9f20", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "a64134fa-af38-4614-aedf-faed2a9f6807", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb", "title": "GPT Action Library: Sharepoint (Return file for Data Analysis / Document Summarization)", "tokens": 4540, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "5c352afb12ac9c7a7bd437a1fb9c093783ec1a6da223932a34f37a0d63a72db8", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 18705, "end_char_idx": 21307, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
'500':
          description: Server error when there are issues executing the query or encoding the results.
```

## Authentication Instructions

Below are instructions on setting up authentication with this 3rd party application. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.

*See above and on the [Azure Function cookbook](https://cookbook.openai.com/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function) for more detailed instructions on authentication.*

## FAQ & Troubleshooting

- Why are you using the Microsoft Graph API in your code instead of the [SharePoint API](https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/get-to-know-the-sharepoint-rest-service?tabs=csom)?

  - The SharePoint API is legacy - per the Microsoft documentation [here](https://learn.microsoft.com/en-us/sharepoint/dev/apis/sharepoint-rest-graph), “For SharePoint Online, innovation using a REST API against SharePoint is driven via the Microsoft Graph REST API's.” The Graph API gives us more flexibility, and the SharePoint API still runs into the same file issues listed in the [Why is this necessary instead of interacting with the Microsoft Graph API directly?](#why-is-this-necessary-instead-of-interacting-with-the-microsoft-api-directly) section.

- What types of files does this support?

  It follows the same guidelines as the documentation [here](https://help.openai.com/en/articles/8555545-file-uploads-faq) about file uploads. 

- Why do I need to request an OBO token?

  - When you try to use the same token to authenticate to the Graph API as the one you use to authenticate into the Azure Function, you get an “invalid audience” token. This is because the audience for the token can only be user\_impersonation.

  - To address this, the function requests a new token scoped to Files.Read.All within the app using the [On Behalf Of flow](https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-on-behalf-of-flow). This will inherit the permissions of the logged in user, meaning this function will only search through files the logged-in user has access to. 

  - We are purposefully requesting a new On Behalf Of token with each request, because Azure Function Apps are meant to be stateless. You could potentially integrate this with Azure Key Vault to store the secret and retrieve programmatically. 

*Are there integrations that you’d like us to prioritize? Are there errors in our integrations? File a PR or issue in our github, and we’ll take a look.*


key: url
string_value:
https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb


key: _node_content
string_value:
{"id_": "f07dc3d3-12d7-4c1a-a63a-7b91525d724c", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb", "title": "GPT Action Library: Gmail", "tokens": 3067, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "27395a83-1993-49f5-80de-1fded65f0389", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb", "title": "GPT Action Library: Gmail", "tokens": 3067, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "4c7a0ed91cae5a94ac501e4cdb5a16d67f5df92023bce088133a45a8487d5cf6", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "72ad6ccf-b981-468b-87bc-a66c523c7506", "node_type": "1", "metadata": {}, "hash": "f856140c7b0a5d694bf611feac6f24a0c9e26d03e7eb662989461beffb70ce34", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 0, "end_char_idx": 2242, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
# GPT Action Library: Gmail

## Introduction

This page provides an instruction & guide for developers building a GPT Action for a specific application. Before you proceed, make sure to first familiarize yourself with the following information: 
- [Introduction to GPT Actions](https://platform.openai.com/docs/actions)
- [Introduction to GPT Actions Library](https://platform.openai.com/docs/actions/actions-library)
- [Example of Building a GPT Action from Scratch](https://platform.openai.com/docs/actions/getting-started)

This GPT Action provides an overview of how to connect to Google Gmail, Google’s Private & Secure Email for Personal or Business. This Action is connected to the Google Gmail APIs that can read, send, list, and draft emails in the authorized account. 

### Value + Example Business Use Cases

**Value**: The Gmail GPT will serve as a powerful tool to streamline communication processes, improve customer engagement, and optimize resource allocation.

**Example Use Cases**: 
- Manage internal communications by summarizing lengthy emails and drafting responses based on previous email threads.
- Support agents can provide customers with instant responses adhering to a company’s communication guidelines, tone, and style.
- Reference other GPTs , such as a data analsys GPT, and then ask for a draft/send of the consolidated analysis through email communication.

## Application Information

### Application Key Links

Check out these links from the application before you get started:
- Application Website: https://mail.google.com/mail/u/0/#inbox
- Application API Documentation: https://developers.google.com/gmail/api/guides

### Application Prerequisites

Before you get started, make sure you’ve a Google Cloud account and that the Gmail API is enabled:
- Set up a Google Cloud project
- Enable Gmail API from Google API Library
- If application’s  “Publishing Status” is “Testing”, ensure users are added to your application

## ChatGPT Steps

### Custom GPT Instructions 

Once you've created a Custom GPT, copy the text below in the Instructions panel. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.


key: _node_content
string_value:
{"id_": "72ad6ccf-b981-468b-87bc-a66c523c7506", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb", "title": "GPT Action Library: Gmail", "tokens": 3067, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "27395a83-1993-49f5-80de-1fded65f0389", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb", "title": "GPT Action Library: Gmail", "tokens": 3067, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "4c7a0ed91cae5a94ac501e4cdb5a16d67f5df92023bce088133a45a8487d5cf6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "f07dc3d3-12d7-4c1a-a63a-7b91525d724c", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb", "title": "GPT Action Library: Gmail", "tokens": 3067, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "57622e903df6f69306d71171947f76d2c7c0a0f3913e789e93d4cb2c4131292a", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "78ca5054-256e-48cc-b946-77c03578a5ab", "node_type": "1", "metadata": {}, "hash": "22b1ead1c96e47155276a438d7665db6e13aa297d3bf0698a44b5520b704b4a4", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 2245, "end_char_idx": 5424, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
```python
**Context**
Act as an email assistant designed to enhance user interaction with emails in various ways. This GPT can assist with productivity by summarizing emails/threads, identifying next steps/follow-ups, drafting or sending pre-written responses, and programmatically interacting with third-party tools (e.g., Notion to-dos, Slack channel summaries, data extraction for responses). This GPT has full scope access to the GMAIL OAuth 2.0 API, capable of reading, composing, sending, and permanently deleting emails from Gmail.

**Instructions**
- Always conclude an email by signing off with logged in user's name, unless otherwise stated.
- Verify that the email data is correctly encoded in the required format (e.g., base64 for the message body).
- Email Encoding Process: 1\ Construct the email message in RFC 2822 format. 2\ Base64 encode the email message. 3\Send the encoded message using the API.
- If not specified, sign all emails with the user name.
- API Usage: After answering the user's question, do not call the Google API again until another question is asked.
- All emails created, draft or sent, should be in plain text.
- Ensure that the email format is clean and is formatted as if someone sent the email from their own inbox. Once a draft is created or email sent, display a message to the user confirming that the draft is ready or the email is sent.
- Check that the "to" email address is valid and in the correct format. It should be in the format "recipient@example.com". 
- Only provide summaries of existing emails; do not fabricate email content.
- Professionalism: Behave professionally, providing clear and concise responses.
- Clarification: Ask for clarification when needed to ensure accuracy and completeness in fulfilling user requests.
- Privacy and Security: Respect user privacy and handle all data securely.

```

### OpenAPI Schema 

Once you've created a Custom GPT, copy the text below in the Actions panel. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.


```python
openapi: 3.1.0
info:
  title: Gmail Email API
  version: 1.0.0
  description: API to read, write, and send emails in a Gmail account.
servers:
  - url: https://gmail.googleapis.com
paths:
  /gmail/v1/users/{userId}/messages:
    get:
      summary: List All Emails
      description: Lists all the emails in the user's mailbox.
      operationId: listAllEmails
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.
        - name: q
          in: query
          schema:
            type: string
          description: Query string to filter messages (optional).
        - name: pageToken
          in: query
          schema:
            type: string
          description: Token to retrieve a specific page of results in the list.
        - name: maxResults
          in: query
          schema:
            type: integer
          description: Maximum number of messages to return.


key: _node_content
string_value:
{"id_": "78ca5054-256e-48cc-b946-77c03578a5ab", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb", "title": "GPT Action Library: Gmail", "tokens": 3067, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "27395a83-1993-49f5-80de-1fded65f0389", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb", "title": "GPT Action Library: Gmail", "tokens": 3067, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "4c7a0ed91cae5a94ac501e4cdb5a16d67f5df92023bce088133a45a8487d5cf6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "72ad6ccf-b981-468b-87bc-a66c523c7506", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb", "title": "GPT Action Library: Gmail", "tokens": 3067, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "1e081b02c200f90ea45629eac7f23bf09e673cf3cd5ec0c75e890826b786a381", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "0cd04cb4-ce49-4a61-ad0d-457042e146b6", "node_type": "1", "metadata": {}, "hash": "72b4dfadacf843e7dcde35de009645e362a2b87208f4d0c0ffe9c61210cdf72f", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 4362, "end_char_idx": 7386, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
```python
openapi: 3.1.0
info:
  title: Gmail Email API
  version: 1.0.0
  description: API to read, write, and send emails in a Gmail account.
servers:
  - url: https://gmail.googleapis.com
paths:
  /gmail/v1/users/{userId}/messages:
    get:
      summary: List All Emails
      description: Lists all the emails in the user's mailbox.
      operationId: listAllEmails
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.
        - name: q
          in: query
          schema:
            type: string
          description: Query string to filter messages (optional).
        - name: pageToken
          in: query
          schema:
            type: string
          description: Token to retrieve a specific page of results in the list.
        - name: maxResults
          in: query
          schema:
            type: integer
          description: Maximum number of messages to return.
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MessageList'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Not Found
        '500':
          description: Internal Server Error
  /gmail/v1/users/{userId}/messages/send:
    post:
      summary: Send Email
      description: Sends a new email.
      operationId: sendEmail
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Message'
      responses:
        '200':
          description: Email sent successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Message'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '500':
          description: Internal Server Error
  /gmail/v1/users/{userId}/messages/{id}:
    get:
      summary: Read Email
      description: Gets the full email content including headers and body.
      operationId: readEmail
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: The ID of the email to retrieve.


key: _node_content
string_value:
{"id_": "0cd04cb4-ce49-4a61-ad0d-457042e146b6", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb", "title": "GPT Action Library: Gmail", "tokens": 3067, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "27395a83-1993-49f5-80de-1fded65f0389", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb", "title": "GPT Action Library: Gmail", "tokens": 3067, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "4c7a0ed91cae5a94ac501e4cdb5a16d67f5df92023bce088133a45a8487d5cf6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "78ca5054-256e-48cc-b946-77c03578a5ab", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb", "title": "GPT Action Library: Gmail", "tokens": 3067, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "aff019c9f87635cc675d4aaa6f737c51afef16298148cc3caec1254bae4b16e8", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "8ac96e96-dd5a-4019-aea4-55dc1bec2722", "node_type": "1", "metadata": {}, "hash": "39eb672ed8cd46e46fae866c265fa5d642f06f7f0f8946f2029ea718714b917f", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 5431, "end_char_idx": 9030, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MessageList'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Not Found
        '500':
          description: Internal Server Error
  /gmail/v1/users/{userId}/messages/send:
    post:
      summary: Send Email
      description: Sends a new email.
      operationId: sendEmail
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Message'
      responses:
        '200':
          description: Email sent successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Message'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '500':
          description: Internal Server Error
  /gmail/v1/users/{userId}/messages/{id}:
    get:
      summary: Read Email
      description: Gets the full email content including headers and body.
      operationId: readEmail
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: The ID of the email to retrieve.
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FullMessage'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Not Found
        '500':
          description: Internal Server Error
  /gmail/v1/users/{userId}/messages/{id}/metadata:
    get:
      summary: Get Email Metadata
      description: Gets the metadata of an email, including subject line.
      operationId: getEmailMetadata
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: The ID of the email to retrieve metadata for.
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MessageMetadata'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Not Found
        '500':
          description: Internal Server Error
  /gmail/v1/users/{userId}/drafts:
    post:
      summary: Create Draft
      description: Creates a new email draft.


key: _node_content
string_value:
{"id_": "8ac96e96-dd5a-4019-aea4-55dc1bec2722", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb", "title": "GPT Action Library: Gmail", "tokens": 3067, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "27395a83-1993-49f5-80de-1fded65f0389", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb", "title": "GPT Action Library: Gmail", "tokens": 3067, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "4c7a0ed91cae5a94ac501e4cdb5a16d67f5df92023bce088133a45a8487d5cf6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "0cd04cb4-ce49-4a61-ad0d-457042e146b6", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb", "title": "GPT Action Library: Gmail", "tokens": 3067, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "c13da90900e71af77aaea87fbbc785558c16b301a50816e43eb54487984a96cc", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "29306626-9c52-4967-ae55-d4bd053f8c8a", "node_type": "1", "metadata": {}, "hash": "ba4f6997770027cc3c3a2bb5de42b4167878f121df076e68bd44b7d0a58d5114", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 7180, "end_char_idx": 10491, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
Use "me" to indicate the authenticated user.
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: The ID of the email to retrieve.
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FullMessage'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Not Found
        '500':
          description: Internal Server Error
  /gmail/v1/users/{userId}/messages/{id}/metadata:
    get:
      summary: Get Email Metadata
      description: Gets the metadata of an email, including subject line.
      operationId: getEmailMetadata
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: The ID of the email to retrieve metadata for.
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MessageMetadata'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Not Found
        '500':
          description: Internal Server Error
  /gmail/v1/users/{userId}/drafts:
    post:
      summary: Create Draft
      description: Creates a new email draft.
      operationId: createDraft
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Draft'
      responses:
        '200':
          description: Draft created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Draft'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '500':
          description: Internal Server Error
components:
  schemas:
    MessageList:
      type: object
      properties:
        messages:
          type: array
          items:
            $ref: '#/components/schemas/Message'
        nextPageToken:
          type: string
    Message:
      type: object
      properties:
        id:
          type: string
        threadId:
          type: string
        labelIds:
          type: array
          items:
            type: string
        snippet:
          type: string
        raw:
          type: string
          format: byte
          description: The entire email message in an RFC 2822 formatted and base64url encoded string.


key: _node_content
string_value:
{"id_": "29306626-9c52-4967-ae55-d4bd053f8c8a", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb", "title": "GPT Action Library: Gmail", "tokens": 3067, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "27395a83-1993-49f5-80de-1fded65f0389", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb", "title": "GPT Action Library: Gmail", "tokens": 3067, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "4c7a0ed91cae5a94ac501e4cdb5a16d67f5df92023bce088133a45a8487d5cf6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "8ac96e96-dd5a-4019-aea4-55dc1bec2722", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb", "title": "GPT Action Library: Gmail", "tokens": 3067, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "e4231ab4130b0ad53107c7628bb2e9dbce50fec9ed0d3e82f9b4e53760463c41", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "949b84d0-ffda-4f9d-b7e7-59448d21d31d", "node_type": "1", "metadata": {}, "hash": "a00ef10ad8a5428dd35989ccc1bdcd60af44b62ac963aa0d103ceeba14ec60ca", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 9037, "end_char_idx": 12907, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
operationId: createDraft
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
          description: The user's email address. Use "me" to indicate the authenticated user.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Draft'
      responses:
        '200':
          description: Draft created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Draft'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '500':
          description: Internal Server Error
components:
  schemas:
    MessageList:
      type: object
      properties:
        messages:
          type: array
          items:
            $ref: '#/components/schemas/Message'
        nextPageToken:
          type: string
    Message:
      type: object
      properties:
        id:
          type: string
        threadId:
          type: string
        labelIds:
          type: array
          items:
            type: string
        snippet:
          type: string
        raw:
          type: string
          format: byte
          description: The entire email message in an RFC 2822 formatted and base64url encoded string.
    FullMessage:
      type: object
      properties:
        id:
          type: string
        threadId:
          type: string
        labelIds:
          type: array
          items:
            type: string
        snippet:
          type: string
        payload:
          type: object
          properties:
            headers:
              type: array
              items:
                type: object
                properties:
                  name:
                    type: string
                  value:
                    type: string
            parts:
              type: array
              items:
                type: object
                properties:
                  mimeType:
                    type: string
                  body:
                    type: object
                    properties:
                      data:
                        type: string
    MessageMetadata:
      type: object
      properties:
        id:
          type: string
        threadId:
          type: string
        labelIds:
          type: array
          items:
            type: string
        snippet:
          type: string
        headers:
          type: array
          items:
            type: object
            properties:
              name:
                type: string
              value:
                type: string
    EmailDraft:
      type: object
      properties:
        to:
          type: array
          items:
            type: string
        cc:
          type: array
          items:
            type: string
        bcc:
          type: array
          items:
            type: string
        subject:
          type: string
        body:
          type: object
          properties:
            mimeType:
              type: string
              enum: [text/plain, text/html]
            content:
              type: string
    Draft:
      type: object
      properties:
        id:
          type: string
        message:
          $ref: '#/components/schemas/Message'
```

## Authentication Instructions

Below are instructions on setting up authentication with this 3rd party application. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.

### Pre-Action Steps

Before you set up authentication in ChatGPT, please take the following steps in the application.


key: _node_content
string_value:
{"id_": "949b84d0-ffda-4f9d-b7e7-59448d21d31d", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb", "title": "GPT Action Library: Gmail", "tokens": 3067, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "27395a83-1993-49f5-80de-1fded65f0389", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb", "title": "GPT Action Library: Gmail", "tokens": 3067, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "4c7a0ed91cae5a94ac501e4cdb5a16d67f5df92023bce088133a45a8487d5cf6", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "29306626-9c52-4967-ae55-d4bd053f8c8a", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_action_gmail.ipynb", "title": "GPT Action Library: Gmail", "tokens": 3067, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "326611deef6469861efd2a34d7f31567d337be9aa58be8a350e2da39305ba00c", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 12635, "end_char_idx": 14819, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.

### Pre-Action Steps

Before you set up authentication in ChatGPT, please take the following steps in the application.


- Go to the Google Cloud Console
- Navigate to API & Services > Credentials

![gptactions_BigQuery_auth.png](../../../images/gptactions_Gmail_enableAPIs.png)

![gptactions_BigQuery_auth.png](../../../images/gptactions_Gmail_gmailApiTile.png)

- Create new OAuth credentials (or use an existing one)

![gptactions_BigQuery_auth.png](../../../images/gptactions_Gmail_apikey.png)

- Locate your OAuth Client ID & Client Secret and store both values securely (see screenshot below)

![gptactions_BigQuery_auth.png](../../../images/gptactions_Gmail_clientidsecret.png)

### In ChatGPT

In ChatGPT, click on "Authentication" and choose **"OAuth"**. Enter in the information below. 

- **Client ID**: use Client ID from steps above 
- **Client Secret**: use Client Secret from steps above
- **Authorization URL**: https://accounts.google.com/o/oauth2/auth
- **Token URL**: https://oauth2.googleapis.com/token 
- **Scope**: https://mail.google.com/
- **Token**: Default (POST)

### Post-Action Steps

Once you've set up authentication in ChatGPT, follow the steps below in the application to finalize the Action. 

- Copy the callback URL from the GPT Action
- In the “Authorized redirect URIs” (see screenshot above), add your callback URL 


### FAQ & Troubleshooting

- *Callback URL Error:* If you get a callback URL error in ChatGPT, pay close attention to the screenshot above. You need to add the callback URL directly into GCP for the action to authenticate correctly
- *Schema calls the wrong project or dataset:* If ChatGPT calls the wrong project or dataset, consider updating your instructions to make it more explicit either (a) which project / dataset should be called or (b) to require the user provide those exact details before it runs the query

*Are there integrations that you’d like us to prioritize? Are there errors in our integrations? File a PR or issue in our github, and we’ll take a look.*


key: url
string_value:
https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb


key: _node_content
string_value:
{"id_": "a22245ec-987d-4b5f-8289-dbe3dc6e2cae", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb", "title": "GPT Action Library (Middleware): Azure Function", "tokens": 2978, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "cc2f67eb-ea39-43cc-81cf-5b8f259f58ec", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb", "title": "GPT Action Library (Middleware): Azure Function", "tokens": 2978, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "d47990d53172b6ae9aaafd601b4733c69d4c6f7526745cf1ae404aa226856417", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "762f77e7-8f3b-42d7-ba11-63bacef70ff8", "node_type": "1", "metadata": {}, "hash": "07d0ef381472c3aac902c12d8867a2bbcf9a254116916977f9b916c778251b20", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 0, "end_char_idx": 3560, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
# GPT Action Library (Middleware): Azure Function

## Introduction

This page provides an instruction & guide for developers building middleware to connect a GPT Action to a specific application. Before you proceed, make sure to first familiarize yourself with the following information: 
- [Introduction to GPT Actions](https://platform.openai.com/docs/actions)
- [Introduction to GPT Actions Library](https://platform.openai.com/docs/actions/actions-library)
- [Example of Building a GPT Action from Scratch](https://platform.openai.com/docs/actions/getting-started)

This particular GPT Action provides an overview of how to build an **Azure Function**, MSFT's cloud-based function builder. This documentation helps a user set up an OAuth-protected Azure Function to connect to a GPT Action, and to a sample application. 

### Value + Example Business Use Cases

**Value**: Users can now leverage ChatGPT's natural language capability to connect directly to Azure Function. This can in a few ways:

- 100k character limit in GPT Actions: users can use the middleware to pre-process the text response from an API. For example, you can use OpenAI’s API in the middleware to summarize the text before sending it back to ChatGPT.
- Typically for actions, users are relying on the SaaS API to return text. You can convert the response for the vendor API into easily digestible text, and it can handle different data types such as structured and unstructured data.
- It can return files instead of just text. This can be useful to surface CSV files for Data Analysis, or bring back an PDF file and ChatGPT will treat it like an upload. 


**Example Use Cases**: 
- A user needs to look up files in Sharepoint, but needs a middleware app between ChatGPT and Sharepoint
- A user has built several steps in a row in an Azure function, and needs to be able to kick off that process using ChatGPT

## Application Information

### Application Key Links

Check out these links from the application before you get started:
- Application Website: https://learn.microsoft.com/en-us/azure/azure-functions/
- Application API Documentation: https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference/

### Application Prerequisites

Before you get started, make sure you go through the following steps in your application environment:
- Azure Portal with access to create Azure Function Apps and Azure Entra App Registrations

## Application Setup

### Installing the app

You can read more about languages and deployment options for Azure Functions on the left hand side of the documentation [here](https://learn.microsoft.com/en-us/azure/azure-functions/functions-overview?pivots=programming-language-csharp). 

#### Option 1: Use VSCode

See Microsoft’s documentation [here](https://learn.microsoft.com/en-us/azure/azure-functions/functions-develop-vs-code?tabs=node-v4,python-v2,isolated-process\&pivots=programming-language-javascript) for how to deploy using VSCode. If you have familiarity with this approach, feel free to use it. 


#### Option 2: Directly in Azure Portal

See the documentation [here](https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-function-app-portal?pivots=programming-language-javascript) for how to deploy using the Azure portal. We’ll walk through an example here step by step.


##### Part 1: Create Function

![](../../../images/create_function_app.png)

1. Create an [Azure Function app](https://learn.microsoft.com/en-us/azure/azure-functions/functions-overview?pivots=programming-language-csharp).


key: _node_content
string_value:
{"id_": "762f77e7-8f3b-42d7-ba11-63bacef70ff8", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb", "title": "GPT Action Library (Middleware): Azure Function", "tokens": 2978, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "cc2f67eb-ea39-43cc-81cf-5b8f259f58ec", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb", "title": "GPT Action Library (Middleware): Azure Function", "tokens": 2978, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "d47990d53172b6ae9aaafd601b4733c69d4c6f7526745cf1ae404aa226856417", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "a22245ec-987d-4b5f-8289-dbe3dc6e2cae", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb", "title": "GPT Action Library (Middleware): Azure Function", "tokens": 2978, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "24fa7c59bea4d90738fb0569f358c7dd2111dd9c3f2192cfd368bd7888fe682f", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "f3e5b245-293f-46ae-82f6-683a3ba8eddc", "node_type": "1", "metadata": {}, "hash": "a09cb77d51b804c5871ae8a0c0d7b2226feca22395a8c3dba5fdcb506a40a03c", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 3042, "end_char_idx": 6299, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
#### Option 2: Directly in Azure Portal

See the documentation [here](https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-function-app-portal?pivots=programming-language-javascript) for how to deploy using the Azure portal. We’ll walk through an example here step by step.


##### Part 1: Create Function

![](../../../images/create_function_app.png)

1. Create an [Azure Function app](https://learn.microsoft.com/en-us/azure/azure-functions/functions-overview?pivots=programming-language-csharp). I used the following settings but you can use anything you are comfortable with. Note that not every language / operating system allows for editing the functions in the console directly - the combination I chose below does. For my walkthrough, I left everything as default and made the selections below. The below settings work out of the box for the SharePoint Node.js solutions [here](https://cookbook.openai.com/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc) and [here](https://cookbook.openai.com/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_text). 

   1. Basics

      1. _Do you want to deploy code or container image?:_  **Code**

      2. _Runtime stack:_ **Node.js**

      3. _Operating system:_ **Windows**

   2. Networking

      1. _Enable public access_: **on (need this on to connect to the GPT)**

2. After completing the above, you’ll land on the “Deployments” page. Once the deployment completes (which should only take a few minutes) click on **“Go to Resource”** to go back to the Function App

  > You may get an error the first time you attempt this, click create again and it will likely work. 

##### Part 2: Set up Auth

3. On the left-hand side menu of the Azure Function App, click on **Authentication** under the **Settings** menu. 

   1. Add identity provider

   2. Select **Microsoft** as identity provider. 

   3. **Workforce** as tenant type

   4. **Create a new application.** The instructions are fairly similar if you are using an existing application, but it is easier to create a new application as it will have the callback URLs and the API exposed automatically using “Easy Auth”. You can read more about that [**here**](https://learn.microsoft.com/en-us/azure/app-service/overview-authentication-authorization).

   5. Leave all the other settings on this page as the default, but feel free to change based on your internal guidelines.

   6. On the **permissions** tab, click **Add Permission** and add **Files.Read.All** and **Sites.ReadAll**, then **Add.** This allows this application to read files which is important in order to use the Microsoft Graph Search API. If you are not using this for the SharePoint solution [here](https://cookbook.openai.com/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc) and [here](https://cookbook.openai.com/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_text) you can skip this.

4. Once it is created, **click on the enterprise application you just created** (so, leave the Function App page and land on the Enterprise Application that you just spun up)**.** We are now going to give it one more permission, to execute the Azure Function by impersonating the user logging into the application.


key: _node_content
string_value:
{"id_": "f3e5b245-293f-46ae-82f6-683a3ba8eddc", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb", "title": "GPT Action Library (Middleware): Azure Function", "tokens": 2978, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "cc2f67eb-ea39-43cc-81cf-5b8f259f58ec", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb", "title": "GPT Action Library (Middleware): Azure Function", "tokens": 2978, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "d47990d53172b6ae9aaafd601b4733c69d4c6f7526745cf1ae404aa226856417", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "762f77e7-8f3b-42d7-ba11-63bacef70ff8", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb", "title": "GPT Action Library (Middleware): Azure Function", "tokens": 2978, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "243329d3a65de4002c2fd0c3868e759df6acb632edc6bf82ab8626ade3e7e31b", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "5539452c-eafe-4c61-8add-d859eb159e63", "node_type": "1", "metadata": {}, "hash": "92bcf7b9e4ec0765c5598717fcb5aee4c88a568626eacf600dc111cf73299949", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 4713, "end_char_idx": 7788, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
##### Part 2: Set up Auth

3. On the left-hand side menu of the Azure Function App, click on **Authentication** under the **Settings** menu. 

   1. Add identity provider

   2. Select **Microsoft** as identity provider. 

   3. **Workforce** as tenant type

   4. **Create a new application.** The instructions are fairly similar if you are using an existing application, but it is easier to create a new application as it will have the callback URLs and the API exposed automatically using “Easy Auth”. You can read more about that [**here**](https://learn.microsoft.com/en-us/azure/app-service/overview-authentication-authorization).

   5. Leave all the other settings on this page as the default, but feel free to change based on your internal guidelines.

   6. On the **permissions** tab, click **Add Permission** and add **Files.Read.All** and **Sites.ReadAll**, then **Add.** This allows this application to read files which is important in order to use the Microsoft Graph Search API. If you are not using this for the SharePoint solution [here](https://cookbook.openai.com/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc) and [here](https://cookbook.openai.com/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_text) you can skip this.

4. Once it is created, **click on the enterprise application you just created** (so, leave the Function App page and land on the Enterprise Application that you just spun up)**.** We are now going to give it one more permission, to execute the Azure Function by impersonating the user logging into the application. See [here](https://learn.microsoft.com/en-us/azure/app-service/configure-authentication-provider-aad?tabs=workforce-tenant) for more details.

   1. On the main page, click “**View API Permissions”**

   2. Search for **Microsoft Azure App Service** in the **APIs my organization uses** and find **user\_impersonation** 

   3. Add it, then you’ll need an Admin on Azure Portal to **Grant Admin Consent.**

5) **Within that enterprise application**, Click on **“Expose an API”** on the left hand menu under **Manage,** then copy the **scope** that was created using the **Copy to Clipboard** button. The scope should look like “api://\<insert-uuid>/user\_impersonation”. **Save this for later as** `SCOPE`**.**

6) Click on **“Authentication”** on the left hand menu under **Manage**

   1. Under the **Web** section, you’ll notice one callback URI was added automatically. Add the Postman redirect URI (<https://oauth.pstmn.io/v1/callback>) for testing.

7) On the left-hand side, go to **Overview**. Copy the **application (client) ID** and and the **directory (tenant) ID** and **save for later as** `CLIENT_ID` **and** `TENANT_ID`**.**

##### Part 3: Set up Test Function

8. Leave the page by going home and then back to your **Function App.**

9. Click on **Create Function.** For this example, I’m going to develop it in the portal, but you can also use VSCode or another IDE.

   1. Choose **HTTP trigger**

   2. For **Authorization Level,** you can choose any key type you want.


key: _node_content
string_value:
{"id_": "5539452c-eafe-4c61-8add-d859eb159e63", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb", "title": "GPT Action Library (Middleware): Azure Function", "tokens": 2978, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "cc2f67eb-ea39-43cc-81cf-5b8f259f58ec", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb", "title": "GPT Action Library (Middleware): Azure Function", "tokens": 2978, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "d47990d53172b6ae9aaafd601b4733c69d4c6f7526745cf1ae404aa226856417", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "f3e5b245-293f-46ae-82f6-683a3ba8eddc", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb", "title": "GPT Action Library (Middleware): Azure Function", "tokens": 2978, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "7233fca013bfa6b397cfd0d8fff7babfaefa039849096dc607529aebeda96fe0", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "c0a236d3-4862-48b6-903d-9924b84a7778", "node_type": "1", "metadata": {}, "hash": "c47f4d62c5ae50566c3f79e698651cf395dd143b6a33fa33ef126c73eaafa630", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 6300, "end_char_idx": 9111, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
See [here](https://learn.microsoft.com/en-us/azure/app-service/configure-authentication-provider-aad?tabs=workforce-tenant) for more details.

   1. On the main page, click “**View API Permissions”**

   2. Search for **Microsoft Azure App Service** in the **APIs my organization uses** and find **user\_impersonation** 

   3. Add it, then you’ll need an Admin on Azure Portal to **Grant Admin Consent.**

5) **Within that enterprise application**, Click on **“Expose an API”** on the left hand menu under **Manage,** then copy the **scope** that was created using the **Copy to Clipboard** button. The scope should look like “api://\<insert-uuid>/user\_impersonation”. **Save this for later as** `SCOPE`**.**

6) Click on **“Authentication”** on the left hand menu under **Manage**

   1. Under the **Web** section, you’ll notice one callback URI was added automatically. Add the Postman redirect URI (<https://oauth.pstmn.io/v1/callback>) for testing.

7) On the left-hand side, go to **Overview**. Copy the **application (client) ID** and and the **directory (tenant) ID** and **save for later as** `CLIENT_ID` **and** `TENANT_ID`**.**

##### Part 3: Set up Test Function

8. Leave the page by going home and then back to your **Function App.**

9. Click on **Create Function.** For this example, I’m going to develop it in the portal, but you can also use VSCode or another IDE.

   1. Choose **HTTP trigger**

   2. For **Authorization Level,** you can choose any key type you want.

      1. Note this may error out the first time, but it is likely the Function did create, do a refresh of the page to check.

10. Click on the function you just created (You may need to click refresh to see it). Click on **Get Function URL** and save it to test in Postman. You will also use this when creating the OpenAPI spec later when you put it into the GPT. 

![](../../../images/get_function_url.png)

11. Go back to the function app and click on **Configuration.** Show the value for the `MICROSOFT_PROVIDER_AUTHENTICATION_SECRET` variable, copy it (click advanced edit to copy it), and **save it for later.**  

At this point, you should have a test function created, and you should have saved a **client id, tenant id, secret, scope, and function URL**. You are now ready to test out the authentication in Postman

##### Part 4: Test Authentication in Postman

12. Try to hit endpoint you created in Postman using those OAuth settings:

    1. **Grant Type:** Authorization Code

    2. **Auth URL**: https://login.microsoftonline.com/`TENANT_ID`/oauth2/v2.0/authorize

    3. **Auth Token URL**: https://login.microsoftonline.com/`TENANT_ID`/oauth2/v2.0/token

    4. **Client ID:** `CLIENT_ID` from step 7 above

    5. **Client secret:** `MICROSOFT_PROVIDER_AUTHENTICATION_SECRET `from step 11 above

    6.


key: _node_content
string_value:
{"id_": "c0a236d3-4862-48b6-903d-9924b84a7778", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb", "title": "GPT Action Library (Middleware): Azure Function", "tokens": 2978, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "cc2f67eb-ea39-43cc-81cf-5b8f259f58ec", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb", "title": "GPT Action Library (Middleware): Azure Function", "tokens": 2978, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "d47990d53172b6ae9aaafd601b4733c69d4c6f7526745cf1ae404aa226856417", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "5539452c-eafe-4c61-8add-d859eb159e63", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb", "title": "GPT Action Library (Middleware): Azure Function", "tokens": 2978, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "0cc9fec501e7213f97ae768597887429cbd59deb6a5d01dfee75be5945475927", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "97f038bc-2b0b-4c8b-bcfb-434a2f4247f4", "node_type": "1", "metadata": {}, "hash": "6041308991761ca8874cb53a990c89a7d9034bb92959e71f02b3d170cf65225c", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 7688, "end_char_idx": 10648, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
1. Choose **HTTP trigger**

   2. For **Authorization Level,** you can choose any key type you want.

      1. Note this may error out the first time, but it is likely the Function did create, do a refresh of the page to check.

10. Click on the function you just created (You may need to click refresh to see it). Click on **Get Function URL** and save it to test in Postman. You will also use this when creating the OpenAPI spec later when you put it into the GPT. 

![](../../../images/get_function_url.png)

11. Go back to the function app and click on **Configuration.** Show the value for the `MICROSOFT_PROVIDER_AUTHENTICATION_SECRET` variable, copy it (click advanced edit to copy it), and **save it for later.**  

At this point, you should have a test function created, and you should have saved a **client id, tenant id, secret, scope, and function URL**. You are now ready to test out the authentication in Postman

##### Part 4: Test Authentication in Postman

12. Try to hit endpoint you created in Postman using those OAuth settings:

    1. **Grant Type:** Authorization Code

    2. **Auth URL**: https://login.microsoftonline.com/`TENANT_ID`/oauth2/v2.0/authorize

    3. **Auth Token URL**: https://login.microsoftonline.com/`TENANT_ID`/oauth2/v2.0/token

    4. **Client ID:** `CLIENT_ID` from step 7 above

    5. **Client secret:** `MICROSOFT_PROVIDER_AUTHENTICATION_SECRET `from step 11 above

    6. **Scope**: `SCOPE` from step 5 above

    7. **Client credentials**: Send client credentials in body

13. You will need to click **Get New Access Token**, and then hit the endpoint you saved in step 10 above. If it was successful, you should get this response: `”This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.”`

##### Part 5: Set up your Application on an Azure Function

This should be done separately and is specific to your app. See the [Sharepoint Cookbook]((https://cookbook.openai.com/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc)) for an example of that. 

##### Part 6: Set up ChatGPT

14. Generate an OpenAPI spec for your endpoint. 

15. Paste that into the Actions section of a GPT, and choose OAuth as the authentication type. Fill out the OAuth settings the same way you did for Postman above. 

16. Once you save the action, you will see a callback URI at the bottom of the GPT configuration. Copy that URL, then go **back to your Function App in the Azure Portal**.

17. Click on **Authentication** under **Settings**, then click on your Entra application.

18. Once you are there, then click **Authentication** under the **Manage** section.

19. Add a new Redirect URI under the **Web** section of that page, and paste in the Callback URI you got from step 16, then click Save. 

20. Test out the GPT and it should work as expected.

## ChatGPT Steps

### Custom GPT Instructions 

*This is application specific.


key: _node_content
string_value:
{"id_": "97f038bc-2b0b-4c8b-bcfb-434a2f4247f4", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb", "title": "GPT Action Library (Middleware): Azure Function", "tokens": 2978, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "cc2f67eb-ea39-43cc-81cf-5b8f259f58ec", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb", "title": "GPT Action Library (Middleware): Azure Function", "tokens": 2978, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "d47990d53172b6ae9aaafd601b4733c69d4c6f7526745cf1ae404aa226856417", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "c0a236d3-4862-48b6-903d-9924b84a7778", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb", "title": "GPT Action Library (Middleware): Azure Function", "tokens": 2978, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "c94d38f67b258f9896c8cff8762ac8751dc310a0180b7e5e7dfef01098e2583e", "class_name": "RelatedNodeInfo"}, "3": {"node_id": "95a79506-69f3-469d-b18e-76c5bd632e1c", "node_type": "1", "metadata": {}, "hash": "3874937e35ba6f2e76bd388e7efaf81022ee3dc004e4e10ded0f1060286d7de7", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 9112, "end_char_idx": 11193, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
**Scope**: `SCOPE` from step 5 above

    7. **Client credentials**: Send client credentials in body

13. You will need to click **Get New Access Token**, and then hit the endpoint you saved in step 10 above. If it was successful, you should get this response: `”This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.”`

##### Part 5: Set up your Application on an Azure Function

This should be done separately and is specific to your app. See the [Sharepoint Cookbook]((https://cookbook.openai.com/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc)) for an example of that. 

##### Part 6: Set up ChatGPT

14. Generate an OpenAPI spec for your endpoint. 

15. Paste that into the Actions section of a GPT, and choose OAuth as the authentication type. Fill out the OAuth settings the same way you did for Postman above. 

16. Once you save the action, you will see a callback URI at the bottom of the GPT configuration. Copy that URL, then go **back to your Function App in the Azure Portal**.

17. Click on **Authentication** under **Settings**, then click on your Entra application.

18. Once you are there, then click **Authentication** under the **Manage** section.

19. Add a new Redirect URI under the **Web** section of that page, and paste in the Callback URI you got from step 16, then click Save. 

20. Test out the GPT and it should work as expected.

## ChatGPT Steps

### Custom GPT Instructions 

*This is application specific. See [Sharepoint Cookbook]((https://cookbook.openai.com/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc)) for an example*

### OpenAPI Schema 

Once you've created a Custom GPT, copy the text below in the Actions panel. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.

Below is an example of what connecting to this Middlware might look like. You'll need to insert your application's & function's information in this section.


key: _node_content
string_value:
{"id_": "95a79506-69f3-469d-b18e-76c5bd632e1c", "embedding": null, "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb", "title": "GPT Action Library (Middleware): Azure Function", "tokens": 2978, "retrieve_doc": true, "source": "openai_cookbooks"}, "excluded_embed_metadata_keys": ["url", "tokens", "retrieve_doc", "source"], "excluded_llm_metadata_keys": ["title", "tokens", "retrieve_doc", "source"], "relationships": {"1": {"node_id": "cc2f67eb-ea39-43cc-81cf-5b8f259f58ec", "node_type": "4", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb", "title": "GPT Action Library (Middleware): Azure Function", "tokens": 2978, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "d47990d53172b6ae9aaafd601b4733c69d4c6f7526745cf1ae404aa226856417", "class_name": "RelatedNodeInfo"}, "2": {"node_id": "97f038bc-2b0b-4c8b-bcfb-434a2f4247f4", "node_type": "1", "metadata": {"url": "https://github.com/openai/openai-cookbook/blob/main/examples/chatgpt/gpt_actions_library/gpt_middleware_azure_function.ipynb", "title": "GPT Action Library (Middleware): Azure Function", "tokens": 2978, "retrieve_doc": true, "source": "openai_cookbooks"}, "hash": "03cdd672bdfd697167c5dde7a516dbe6a63fb42e285d6ab2828527e570f81897", "class_name": "RelatedNodeInfo"}}, "text": "", "mimetype": "text/plain", "start_char_idx": 9634, "end_char_idx": 12713, "text_template": "{metadata_str}\n\n{content}", "metadata_template": "{key}: {value}", "metadata_seperator": "\n", "class_name": "TextNode"}


key: chroma:document
string_value:
See the [Sharepoint Cookbook]((https://cookbook.openai.com/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc)) for an example of that. 

##### Part 6: Set up ChatGPT

14. Generate an OpenAPI spec for your endpoint. 

15. Paste that into the Actions section of a GPT, and choose OAuth as the authentication type. Fill out the OAuth settings the same way you did for Postman above. 

16. Once you save the action, you will see a callback URI at the bottom of the GPT configuration. Copy that URL, then go **back to your Function App in the Azure Portal**.

17. Click on **Authentication** under **Settings**, then click on your Entra application.

18. Once you are there, then click **Authentication** under the **Manage** section.

19. Add a new Redirect URI under the **Web** section of that page, and paste in the Callback URI you got from step 16, then click Save. 

20. Test out the GPT and it should work as expected.

## ChatGPT Steps

### Custom GPT Instructions 

*This is application specific. See [Sharepoint Cookbook]((https://cookbook.openai.com/examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc)) for an example*

### OpenAPI Schema 

Once you've created a Custom GPT, copy the text below in the Actions panel. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.

Below is an example of what connecting to this Middlware might look like. You'll need to insert your application's & function's information in this section. 


```python
openapi: 3.1.0
info:
  title: {insert title}
  description: {insert description}
  version: 1.0.0
servers:
  - url: https://{your_function_app_name}.azurewebsites.net/api
    description: {insert description}
paths:
  /{your_function_name}?code={enter your specific endpoint id here}:
    post:
      operationId: {insert operationID}
      summary: {insert summary}
      requestBody: 
{the rest of this is specific to your application}
```

## Authentication Instructions

Below are instructions on setting up authentication with this 3rd party application. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.

### Pre-Action Steps

Before you set up authentication in ChatGPT, please take the following steps in the application.

*Follow steps 2 & 4 above to setting up authentication*

### In ChatGPT

In ChatGPT, click on "Authentication" and choose **"OAuth"**. Enter in the information below. 

- **Client ID**: *see step 12 above*
- **Client Secret**: *ditto*
- **Authorization URL**: *ditto*
- **Token URL**: *ditto*
- **Scope**: *ditto*
- **Token**: *ditto*

### Post-Action Steps

Once you've set up authentication in ChatGPT, follow the steps below in the application to finalize the Action. 

*See above for testing out this application*

*Are there integrations that you’d like us to prioritize? Are there errors in our integrations? File a PR or issue in our github, and we’ll take a look.*


