Skip to content

Latest commit

 

History

History
143 lines (98 loc) · 4.45 KB

snippets.md

File metadata and controls

143 lines (98 loc) · 4.45 KB

Snippets

SnippetsApi snippetsApi = client.getSnippetsApi();

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.

CompletableFuture<DeleteSnippetResponse> deleteSnippetAsync(
    final String siteId)

Parameters

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

Response Type

DeleteSnippetResponse

Example Usage

String siteId = "site_id6";

snippetsApi.deleteSnippetAsync(siteId).thenAccept(result -> {
    // TODO success callback handler
    System.out.println(result);
}).exceptionally(exception -> {
    // TODO failure callback handler
    exception.printStackTrace();
    return null;
});

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.

CompletableFuture<RetrieveSnippetResponse> retrieveSnippetAsync(
    final String siteId)

Parameters

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

Response Type

RetrieveSnippetResponse

Example Usage

String siteId = "site_id6";

snippetsApi.retrieveSnippetAsync(siteId).thenAccept(result -> {
    // TODO success callback handler
    System.out.println(result);
}).exceptionally(exception -> {
    // TODO failure callback handler
    exception.printStackTrace();
    return null;
});

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.

CompletableFuture<UpsertSnippetResponse> upsertSnippetAsync(
    final String siteId,
    final UpsertSnippetRequest body)

Parameters

Parameter Type Tags Description
siteId String Template, Required The ID of the site where you want to add or update the snippet.
body UpsertSnippetRequest Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

UpsertSnippetResponse

Example Usage

String siteId = "site_id6";
UpsertSnippetRequest body = new UpsertSnippetRequest.Builder(
    new Snippet.Builder(
        "<script>var js = 1;</script>"
    )
    .build()
)
.build();

snippetsApi.upsertSnippetAsync(siteId, body).thenAccept(result -> {
    // TODO success callback handler
    System.out.println(result);
}).exceptionally(exception -> {
    // TODO failure callback handler
    exception.printStackTrace();
    return null;
});