Applies to:
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
Note
Square Online APIs are publicly available as part of an early access program. For more information, see
The head
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
The following is an example request. To get the site ID, call the
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
The
The following is an example request. To get the site ID, call the
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
The following is an example request. To get the site ID, call the
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." } ] }