Issue with 404 error when writing to Supabase: Is the code and URL correct?

This topic was automatically generated from Slack. You can find the original thread here.

Does this look right for writing to supabase? For some reason I’m getting 404, but I’m verifying the url it’s conencting to is “correct” .

 # Function to insert job data into Supabase
    def insert_data(data):
        token = f'{pd.inputs["supabase"]["$auth"]["service_key"]}'
        authorization = f'Bearer {token}'
        headers = {
            "Authorization": authorization,
            "apikey": f'{token}',
            "Content-Type": "application/json"
        }
        url = f'https://{pd.inputs["supabase"]["$auth"]["subdomain"]}.[supabase.co/rest/v1/](http://supabase.co/rest/v1/)'

How to connect to Supabase using Python Code step in Pipedream

To connect to Supabase using a Python code step in Pipedream, you can use the requests library to make HTTP requests to the Supabase API. Here’s an example of how to do this: 1. First, add a Python code step in your Pipedream workflow. 2. In the code step, import the requests library and use it to make API calls to Supabase. python import requests supabase_url = "https://your-supabase-url.supabase.co" supabase_key = "your-supabase-key" headers = { "apikey": supabase_key, "Content-Type": "application/json", } # Replace "your_table" with the name of your Supabase table response = requests.get(f"{supabase_url}/rest/v1/your_table", headers=headers) data = response.json() print(data) Make sure to replace your-supabase-url and your-supabase-key with your actual Supabase URL and API key. Also, replace your_table with the name of the table you want to query in your Supabase database. This example demonstrates a simple GET request to fetch data from a Supabase table. You can modify the code to perform other operations like inserting, updating, or deleting data by referring to the Supabase API documentation.

I think the code by the AI is incorrect.

On another note, I think the url url = f'https://{pd.inputs["supabase"]["$auth"] is bad. Could you use string instead?

import requests
import supabase


from supabase import create_client, Client

def handler(pd: "pipedream"):
    # Retrieve the processed data from the previous step
    processed_data = pd.steps["transform"]["$return_value"]

    # Initialize Supabase client
    url = f'https://{pd.inputs["supabase"]["$auth"]["subdomain"]}.[supabase.co](http://supabase.co)'
    service_key = f'{pd.inputs["supabase"]["$auth"]["service_key"]}'
    supabase: SupabaseClient = create_client(url, service_key)

    # Function to upsert job data into Supabase
    def upsert_data(data):
        response = supabase.table('table').upsert(data).execute()
        return response

    # Upsert data into Supabase and store the response status codes
    response_status_codes = [upsert_data(record) for record in processed_data]

    # Return the response status codes for debugging purposes
    return response_status_codes

This ended up getting me there. I didn’t think to use the supabase module within pipedream. (First day playing around with both).

Interesting though, the $auth seems to come from how pipedream passes auth from integrated services. Weird, I didn’t even know you could have a $ in a key of a dict.