Update Agent Sharing and Get Agent Share Link Using CustomGPT RAG API – A Detailed Guide

Author Image

Written by: Priyansh Khodiyar

Update Agent Sharing and Get Agent Share Link Using CustomGPT RAG API

Watch the video at the top of the post for a live demo and walkthrough of this guide! (coming soon)

1. Introduction

Hi there! In this guide, we’re going to show you how to update your project’s sharing status and retrieve your agent share link, embed code, and live chat code using the CustomGPT RAG API in a Google Colab notebook. Even though the code still uses the term “project,” many of us refer to these as “agents.” Whether you want to share your chatbot with others or embed it on your website, this guide will walk you through each step in great detail. Let’s get started!

Make sure you have read our Getting Started with CustomGPT.ai for New Developers blog to get an overview of the entire platform.

By the end, you’ll be able to programmatically inspect where your chatbot’s content comes from. For full API reference, see the CustomGPT API docs.

Cookbook – https://github.com/Poll-The-People/customgpt-cookbook/blob/main/examples/Update_project_sharing_and_get_project_share_link%2C_embed_code_and_chat_js_code.ipynb

2. Setting Up the Environment

Before we dive into the functionality, you need to set up your workspace in Google Colab. This includes configuring the API endpoint, your API token, and importing the required libraries.

# setup API URL and API Token

api_endpoint = 'https://app.customgpt.ai/api/v1/'

api_token = 'ADD_YOUR_API_TOKEN_HERE'

headers = {

    'Content-type': 'application/json',

    'Authorization': 'Bearer ' + api_token

}

# imports

import requests

import json

What This Does:

  • API Endpoint & Token:
    Specifies the base URL for the API and secures your requests using your API token. (Remember to replace ‘ADD_YOUR_API_TOKEN_HERE’ with your actual token.)
  • Headers:
    Sets the HTTP headers, including the content type (JSON) and your authorization information.
  • Imports:
    Imports the requests library for making HTTP calls and the json module to work with JSON data.

Get API keys

To get your API key, there are two ways:

Method 1 – Via Agent

  1. Agent > All Agents.
  2. Select your agent and go to deploy, click on the API key section and create an API. 

Method 2 – Via Profile section.

  1. Go to profile (top right corner of your screen)
  2. Click on My Profile
  3. You will see the screen something like this (below screenshot). Here you can click on “Create API key”, give it a name and copy the key.
Create API

Please save this secret key somewhere safe and accessible. For security reasons, You won’t be able to view it again through your CustomGPT.ai account. If you lose this secret key, you’ll need to generate a new one.

Now that our environment is configured, let’s move on to creating an agent.

3. Creating an Agent (Project) for Your Account

In this step, you create a new agent (project) using a sitemap as the content source. This agent acts as the foundation that you’ll later share with others.

**Create a project for the account**

# Give a name to your project

project_name = 'Example ChatBot using Sitemap'

sitemap_path = 'https://adorosario.github.io/small-sitemap.xml'

payload = json.dumps({

    "project_name": project_name,

    "sitemap_path": sitemap_path

})

url = api_endpoint + 'projects'

create_project = requests.request('POST', url, headers=headers, data=payload)

print(create_project.text)

What This Does:

  • Agent Details:
    Sets the name of your agent and defines the sitemap URL that serves as the content source.
  • Payload Creation:
    Converts these details into JSON format so the API can understand your request.
  • POST Request:
    Sends the data to the CustomGPT API to create your agent.
  • Output:
    Prints the JSON response containing the agent’s details, including its unique ID (for example, “id”:508).

Great! With your agent successfully created, it’s time to update its sharing status.

4. Updating Project Sharing Status

In order to share your agent or embed it in a website, you need to update its sharing status. This step sets the agent as shared, which enables you to retrieve the share link and other embed codes.

**Update project sharing status**

data = json.loads(create_project.text)["data"]

project_id = data["id"]

payload = json.dumps({

    "is_shared": True

})

# Update the project

url = api_endpoint + 'projects' + f"/{project_id}"

update_project = requests.request('POST', url, headers=headers, data=payload)

What This Does:

  • Extract Agent ID:
    Parses the JSON response from the project creation step to extract the unique project_id.
  • Payload for Sharing:
    Creates a payload that sets “is_shared”: True, enabling sharing for your agent.
  • POST Request for Update:
    Sends a request to the project-specific URL to update the sharing status.

With your agent now set to be shared, let’s retrieve the share link and associated codes.

5. Retrieving the Share Link, Embed Code, and Live Chat Code

After updating the sharing status, you can get the shareable link, embed code, and the live chat code required to integrate your agent with your website or share it with others.

**Get Share Link, embed code and livechat**

# Check status of the project if chat bot is active

data = json.loads(update_project.text)["data"]

share_link = data['shareable_link']

print('Share Link')

print(share_link)

embed_code = data['embed_code']

print('Embed Code')

print(embed_code)

live_chat_code = data['live_chat_code']

print('Live Chat Code')

print(live_chat_code)

What This Does:

  • Extract Sharing Data:
    Parses the JSON response from the update call to retrieve the agent’s sharing details.
  • Share Link:
    Retrieves and prints the shareable link. This link allows others to access the conversation interface, for example:
    https://dev.customgpt.ai/api/v1/projects/508/conversations?shareable_slug=4f5293ab51ff008006c4ba33cfc6c8fb.
  • Embed Code:
    Retrieves and prints the HTML embed code. You can use this code to embed the chat interface on your website.
  • Live Chat Code:
    Retrieves and prints the live chat initialization script. This script can be included in your web pages to enable live chat functionality.

After following this section, your agent will be sharable and ready for embedding. Let’s quickly run through some common troubleshooting tips before wrapping up.

6. Troubleshooting Common Issues

Here are some common issues you might encounter and a few troubleshooting tips:

  • Invalid API Token:
    Ensure you’ve replaced ‘ADD_YOUR_API_TOKEN_HERE’ with a valid API token.
  • JSON Formatting Errors:
    Verify that your JSON payloads are correctly formatted before sending API requests.
  • Connection Problems:
    Make sure your internet connection is stable and the API endpoint URL is correct.
  • Unexpected API Responses:
    If the response does not match the sample output, print the raw response for debugging and consult the CustomGPT API documentation for guidance.

If you run into any problems, these tips should help you identify and fix the issue.

7. Conclusion

Congratulations! In this guide, you learned how to:

  • Set up your Google Colab environment with the necessary API configurations.
  • Create an agent (project) using a sitemap as your content source.
  • Update the agent’s sharing status to enable sharing.
  • Retrieve the share link, embed code, and live chat code for your agent.

These steps give you the tools to share your chatbot easily, whether through a direct link or by embedding it on your website. If you have any questions or need further assistance, feel free to check out the CustomGPT documentation or join our community for support.

Happy coding, and enjoy sharing your custom chatbot solutions with CustomGPT!

Build a Custom GPT for your business, in minutes.

Deliver exceptional customer experiences and maximize employee efficiency with custom AI agents.

Trusted by thousands of organizations worldwide

Related posts

Leave a reply

Your email address will not be published. Required fields are marked *

*

3x productivity.
Cut costs in half.

Launch a custom AI agent in minutes.

Instantly access all your data.
Automate customer service.
Streamline employee training.
Accelerate research.
Gain customer insights.

Try 100% free. Cancel anytime.