A Weebly app can include a snippet, which is a piece of HTML code that is installed and runs on the front-end of a web site. Snippets are usually used to generate a

​Use the Snippet API to retrieve, create, update, or delete a snippet on a site.

Fields

The following table shows all fields that exist for this API, and those that are changeable and required using POST. All fields are returned when you retrieve a single item.

Name Description Type Required Changeable
user_id The unique ID of the authenticated user string
site_id ID of a Weebly site, unique to the currently authenticated user​ string
snippet HTML snippet for this app added to all pages on the site string X X

GET
Retrieve an App's Snippet for a Site

GET /v1/user/sites/{SITE_ID}/snippet

Returns the snippet for the app created for this site. The app ID is determined by the OAuth token.

scope: read:site

Example CURL request:

curl --request GET \
    --url https://api.weebly.com/v1/user/sites/987654321/snippet \
    --header 'accept: application/vnd.weebly.v1+json' \
    --header 'content-type: application/json' \
    --header 'x-weebly-access-token: [YOUR_TOKEN]'

Example response:

{
    "user_id": "123456",
    "site_id": "987654321",
    "snippet": "<h1>My App Snippet</h1>"
}

POST
Create or Update an App's Snippet for a Site

POST /v1/user/sites/{SITE_ID}/snippet

Updates a site’s snippet by replacing the HTML. If a snippet did not already exist on the page, then adds the new snippet.

scope: write:site

Updateable Fields

These fields can be updated:

Name Description Type Notes
snippet HTML snippet for this app added to all pages on the site string Required

Example CURL request:

curl --request POST \
    --url https://api.weebly.com/v1/user/sites/987654321/snippet \
    --header 'accept: application/vnd.weebly.v1+json' \
    --header 'content-type: application/json' \
    --header 'x-weebly-access-token: [YOUR_TOKEN]"' \
    --data '{
                "snippet": "<p>My new HTML</p>"
            }'

Example response:

{
    "user_id": "123456",
    "site_id": "987654321",
    "snippet": "<p>My new HTML</p>"
}

DELETE
Delete an App's Snippet from a Site

DELETE /v1/user/sites/{SITE_ID}/snippet

Deletes the snippet from the site.

scope: write:site

Example CURL request:

curl --request DELETE \
    --url https://api.weebly.com/v1/user/sites/987654321/snippet \
    --header 'accept: application/vnd.weebly.v1+json' \
    --header 'content-type: application/json' \
    --header 'x-weebly-access-token: [YOUR_TOKEN]"' \

Response

There is no response to a delete request.


Help make these docs better!









Tags:
snippets apis