Skip to content

Latest commit

 

History

History
137 lines (89 loc) · 3.95 KB

snippets.md

File metadata and controls

137 lines (89 loc) · 3.95 KB

Snippets

snippets_api = client.snippets

Class Name

SnippetsApi

Methods

Delete Snippet

Removes your snippet from a Square Online site.

You can call ListSites to get the IDs of the sites that belong to a seller.

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.

def delete_snippet(self,
                  site_id)

Parameters

Parameter Type Tags Description
site_id string Template, Required The ID of the site that contains the snippet.

Response Type

Delete Snippet Response

Example Usage

site_id = 'site_id6'

result = snippets_api.delete_snippet(site_id)

if result.is_success():
    print(result.body)
elif result.is_error():
    print(result.errors)

Retrieve Snippet

Retrieves your snippet from a Square Online site. A site can contain snippets from multiple snippet applications, but you can retrieve only the snippet that was added by your application.

You can call ListSites to get the IDs of the sites that belong to a seller.

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.

def retrieve_snippet(self,
                    site_id)

Parameters

Parameter Type Tags Description
site_id string Template, Required The ID of the site that contains the snippet.

Response Type

Retrieve Snippet Response

Example Usage

site_id = 'site_id6'

result = snippets_api.retrieve_snippet(site_id)

if result.is_success():
    print(result.body)
elif result.is_error():
    print(result.errors)

Upsert Snippet

Adds a snippet to a Square Online site or updates the existing snippet on the site. The snippet code is appended to the end of the head element on every page of the site, except checkout pages. A snippet application can add one snippet to a given site.

You can call ListSites to get the IDs of the sites that belong to a seller.

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.

def upsert_snippet(self,
                  site_id,
                  body)

Parameters

Parameter Type Tags Description
site_id string Template, Required The ID of the site where you want to add or update the snippet.
body Upsert Snippet Request Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

Upsert Snippet Response

Example Usage

site_id = 'site_id6'
body = {}
body['snippet'] = {}
body['snippet']['id'] = 'id4'
body['snippet']['site_id'] = 'site_id0'
body['snippet']['content'] = '<script>var js = 1;</script>'
body['snippet']['created_at'] = 'created_at8'
body['snippet']['updated_at'] = 'updated_at0'

result = snippets_api.upsert_snippet(site_id, body)

if result.is_success():
    print(result.body)
elif result.is_error():
    print(result.errors)