Applies to: Snippets API
Learn how to use the Snippets API to manage snippets for Square Online sites.
You can use the Snippets API to manage a snippet on a Square Online site. Snippets add custom functionality to Square Online sites. For more information, see Snippets API
Note
Square Online APIs are publicly available as part of an early access program. For more information, see Early access program for Square Online APIs.
The UpsertSnippethead
tag on every page of the site, except for checkout pages. Snippet code is sent as a string that contains valid HTML, CSS, JavaScript, or a combination of the three. The string has a maximum length of 65,535 characters.
An application can create and manage one snippet on any given site. For an example workflow, see Add a Snippet to a Site
The following is an example request. To get the site ID, call the ListSites
Upsert snippet
If successful, this endpoint returns a 200 OK
status code and a response similar to the following example:
{ "snippet": { "id": "snippet_5d178150-a6c0-11eb-a9f1-437e6example", "site_id": "site_27807527648example", "content": "<script type=\"text/javascript\">var js = 1;</script>", "created_at": "2021-03-11T25:40:09.000000Z", "updated_at": "2021-03-11T25:40:09.000000Z" } }
Note
The snippet ID isn't required for requests to the Snippets API because an application can add only one snippet to a site.
If the site cannot be found, this endpoint returns a 404 Not Found
status code and the following response:
{ "errors": [ { "category": "INVALID_REQUEST_ERROR", "code": "NOT_FOUND", "detail": "Resource not found." } ] }
Note
If you encounter issues when running cURL commands from a terminal window (such as valid snippet code that returns a BAD_REQUEST
error or encoded HTML in the response), try using API Explorer
The RetrieveSnippet
The following is an example request. To get the site ID, call the ListSites
Retrieve snippet
If successful, this endpoint returns a 200 OK
status code and a response similar to the following example:
{ "snippet": { "id": "snippet_5d178150-a6c0-11eb-a9f1-437e6example", "site_id": "site_27807527648example", "content": "<script type=\"text/javascript\">var js = 1;</script>", "created_at": "2021-03-11T25:40:09.000000Z", "updated_at": "2021-03-11T25:40:09.000000Z" } }
If the snippet cannot be found, this endpoint returns a 404 Not Found
status code and the following response:
{ "errors": [ { "category": "INVALID_REQUEST_ERROR", "code": "NOT_FOUND", "detail": "Resource not found." } ] }
The DeleteSnippet
The following is an example request. To get the site ID, call the ListSites
Delete snippet
If successful, this endpoint returns a 200 OK
status code and an empty JSON object:
{}
If there is no snippet for the specified site, this endpoint returns a 404 Not Found
status code and the following response:
{ "errors": [ { "category": "INVALID_REQUEST_ERROR", "code": "NOT_FOUND", "detail": "Resource not found." } ] }