API Example

Parameters

Parameter Description Location
id ID of the paste you want to edit. Body (JSON)
edit_code Required code to edit the paste. Body (JSON)
new.content New content of the paste. Body (JSON)

Code

# Basic API example for EDITING your paste.

import requests

PASTE_ID = "PASTE_ID_HERE"
EDIT_CODE = "PASTE_EDIT_CODE_HERE"

NEW_MESSAGE = "Your new paste content."

try:
    response = requests.patch(
        "<https://paster.so/api/v3/pastes/markdown>",
        headers={"Content-Type": "application/json"},
        json={
            "id": PASTE_ID,
            "edit_code": EDIT_CODE,
            "new": {"content": NEW_MESSAGE}
        }
    )
    response_data = response.json()
    paste_data = response_data.get("data", {})

    if paste_data.get("url"):
        print(paste_data)
    else:
        print("Response did not contain a URL:", response_data)
except requests.exceptions.RequestException as e:
    print("Error making the request:", e)