Skip to content

Latest commit

 

History

History
142 lines (93 loc) · 4.24 KB

snippets.md

File metadata and controls

142 lines (93 loc) · 4.24 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 str Template, Required The ID of the site that contains the snippet.

Response Type

This method returns a ApiResponse instance. The body property of this instance returns the response data which is of type Delete Snippet Response.

Example Usage

site_id = 'site_id6'

result = snippets_api.delete_snippet(site_id)
print(result)

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 str Template, Required The ID of the site that contains the snippet.

Response Type

This method returns a ApiResponse instance. The body property of this instance returns the response data which is of type Retrieve Snippet Response.

Example Usage

site_id = 'site_id6'

result = snippets_api.retrieve_snippet(site_id)
print(result)

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 str 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

This method returns a ApiResponse instance. The body property of this instance returns the response data which is of type Upsert Snippet Response.

Example Usage

site_id = 'site_id6'

body = {
    'snippet': {
        'content': '<script>var js = 1;</script>'
    }
}

result = snippets_api.upsert_snippet(
    site_id,
    body
)
print(result)

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