Skip to content

Latest commit

 

History

History
142 lines (90 loc) · 4.14 KB

snippets.md

File metadata and controls

142 lines (90 loc) · 4.14 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(site_id:)

Parameters

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

Response Type

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

Example Usage

site_id = 'site_id6'


result = snippets_api.delete_snippet(site_id: site_id)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

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(site_id:)

Parameters

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

Response Type

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

Example Usage

site_id = 'site_id6'


result = snippets_api.retrieve_snippet(site_id: site_id)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

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(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 Hash 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 data property in this instance returns the response data which is of type Upsert Snippet Response Hash.

Example Usage

site_id = 'site_id6'

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


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

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end