Square Connect .NET SDK Technical Reference

December 17, 2019 ยท View on GitHub

Square logo

Square Connect .NET SDK Technical Reference


The Square Connect .NET SDK is retired (EOL) as of 2019-12-17 and will no longer receive bug fixes or product updates.


Build Status NuGet version Apache-2 license

If you have feedback about the new SDKs, or just want to talk to other Square Developers, request an invite to the new slack community for Square Developers

This repository contains the released C# client SDK. Check out our API specification repository for the specification and template files we used to generate this.

Frameworks supported

  • .NET Standard 2.0

Usage

PM> Install-Package Square.Connect

Option 2: Generating DLLs from source

Dependencies

Option 1: Run the following command to generate the DLL

  • [Mac/Linux] /bin/sh build.sh
  • [Windows] build.bat

Option 2: Import the Square.Connect/Square.Connect.csproj to your solution and build from VS

Then include the DLLs (under the bin folder) in the C# project,

  • Square.Connect.dll

Getting Started

Use the namespaces:

using Square.Connect.Api;
using Square.Connect.Client;
using Square.Connect.Model;

Example:

using System;
using System.Diagnostics;
using Square.Connect.Api;
using Square.Connect.Client;
using Square.Connect.Model;

namespace Example
{
    public class Example
    {
        readonly Configuration configuration;
        public Example()
        {
            this.configuration = new Configuration(new ApiClient("https://connect.squareup.com"));
            this.configuration.AccessToken = "YOUR_ACCESS_TOKEN";
        }

        // Retrieving your location IDs
        public void RetrieveLocations()
        {
            LocationsApi _locationsApi = new LocationsApi(this.configuration);
            var response = _locationsApi.ListLocations();
        }

        // Charge the card nonce
        public void ChargeNonce()
        {
            // Every payment you process for a given business have a unique idempotency key.
            // If you're unsure whether a particular payment succeeded, you can reattempt
            // it with the same idempotency key without worrying about double charging
            // the buyer.
            string idempotencyKey = Guid.NewGuid().ToString();

            // Monetary amounts are specified in the smallest unit of the applicable currency.
            // This amount is in cents. It's also hard-coded for \$1, which is not very useful.
            int amount = 100;
            string currency = "USD";
            Money money = new Money(amount, currency);

            string nonce = "YOUR_NONCE";
            string locationId = "YOUR_LOCATION_ID";
            CreatePaymentRequest body = new CreatePaymentRequest(SourceId: nonce, IdempotencyKey: idempotencyKey, AmountMoney: money, LocationId: locationId);
            PaymentsApi paymentsApi = new PaymentsApi(this.configuration);
            var response = paymentsApi.CreatePayment(body);
        }
    }
}

More examples are available at connect-api-examples

How to configure sandbox environment

using System;
using System.Diagnostics;
using Square.Connect.Api;
using Square.Connect.Client;
using Square.Connect.Model;

namespace Example
{
    public class Example
    {
        readonly Configuration configuration;
        public Example()
        {
            this.configuration = new Configuration(new ApiClient("https://connect.squareupsandbox.com"));
            this.configuration.AccessToken = "YOUR_SANDBOX_ACCESS_TOKEN";
            LocationsApi locationsApi = new LocationsApi(this.configuration);
        }
    }
}

Documentation for API Endpoints

All URIs are relative to Square Connect Documentation

ClassMethodHTTP request
ApplePayApiRegisterDomainPOST /v2/apple-pay/domains
CatalogApiBatchDeleteCatalogObjectsPOST /v2/catalog/batch-delete
CatalogApiBatchRetrieveCatalogObjectsPOST /v2/catalog/batch-retrieve
CatalogApiBatchUpsertCatalogObjectsPOST /v2/catalog/batch-upsert
CatalogApiCatalogInfoGET /v2/catalog/info
CatalogApiDeleteCatalogObjectDELETE /v2/catalog/object/{object_id}
CatalogApiListCatalogGET /v2/catalog/list
CatalogApiRetrieveCatalogObjectGET /v2/catalog/object/{object_id}
CatalogApiSearchCatalogObjectsPOST /v2/catalog/search
CatalogApiUpdateItemModifierListsPOST /v2/catalog/update-item-modifier-lists
CatalogApiUpdateItemTaxesPOST /v2/catalog/update-item-taxes
CatalogApiUpsertCatalogObjectPOST /v2/catalog/object
CheckoutApiCreateCheckoutPOST /v2/locations/{location_id}/checkouts
CustomersApiCreateCustomerPOST /v2/customers
CustomersApiCreateCustomerCardPOST /v2/customers/{customer_id}/cards
CustomersApiDeleteCustomerDELETE /v2/customers/{customer_id}
CustomersApiDeleteCustomerCardDELETE /v2/customers/{customer_id}/cards/{card_id}
CustomersApiListCustomersGET /v2/customers
CustomersApiRetrieveCustomerGET /v2/customers/{customer_id}
CustomersApiSearchCustomersPOST /v2/customers/search
CustomersApiUpdateCustomerPUT /v2/customers/{customer_id}
EmployeesApiListEmployeesGET /v2/employees
EmployeesApiRetrieveEmployeeGET /v2/employees/{id}
InventoryApiBatchChangeInventoryPOST /v2/inventory/batch-change
InventoryApiBatchRetrieveInventoryChangesPOST /v2/inventory/batch-retrieve-changes
InventoryApiBatchRetrieveInventoryCountsPOST /v2/inventory/batch-retrieve-counts
InventoryApiRetrieveInventoryAdjustmentGET /v2/inventory/adjustment/{adjustment_id}
InventoryApiRetrieveInventoryChangesGET /v2/inventory/{catalog_object_id}/changes
InventoryApiRetrieveInventoryCountGET /v2/inventory/{catalog_object_id}
InventoryApiRetrieveInventoryPhysicalCountGET /v2/inventory/physical-count/{physical_count_id}
LaborApiCreateBreakTypePOST /v2/labor/break-types
LaborApiCreateShiftPOST /v2/labor/shifts
LaborApiDeleteBreakTypeDELETE /v2/labor/break-types/{id}
LaborApiDeleteShiftDELETE /v2/labor/shifts/{id}
LaborApiGetBreakTypeGET /v2/labor/break-types/{id}
LaborApiGetEmployeeWageGET /v2/labor/employee-wages/{id}
LaborApiGetShiftGET /v2/labor/shifts/{id}
LaborApiListBreakTypesGET /v2/labor/break-types
LaborApiListEmployeeWagesGET /v2/labor/employee-wages
LaborApiListWorkweekConfigsGET /v2/labor/workweek-configs
LaborApiSearchShiftsPOST /v2/labor/shifts/search
LaborApiUpdateBreakTypePUT /v2/labor/break-types/{id}
LaborApiUpdateShiftPUT /v2/labor/shifts/{id}
LaborApiUpdateWorkweekConfigPUT /v2/labor/workweek-configs/{id}
LocationsApiCreateLocationPOST /v2/locations
LocationsApiListLocationsGET /v2/locations
LocationsApiRetrieveLocationGET /v2/locations/{location_id}
LocationsApiUpdateLocationPUT /v2/locations/{location_id}
MerchantsApiListMerchantsGET /v2/merchants
MerchantsApiRetrieveMerchantGET /v2/merchants/{merchant_id}
MobileAuthorizationApiCreateMobileAuthorizationCodePOST /mobile/authorization-code
OAuthApiObtainTokenPOST /oauth2/token
OAuthApiRenewTokenPOST /oauth2/clients/{client_id}/access-token/renew
OAuthApiRevokeTokenPOST /oauth2/revoke
OrdersApiBatchRetrieveOrdersPOST /v2/locations/{location_id}/orders/batch-retrieve
OrdersApiCreateOrderPOST /v2/locations/{location_id}/orders
OrdersApiPayOrderPOST /v2/orders/{order_id}/pay
OrdersApiSearchOrdersPOST /v2/orders/search
OrdersApiUpdateOrderPUT /v2/locations/{location_id}/orders/{order_id}
PaymentsApiCancelPaymentPOST /v2/payments/{payment_id}/cancel
PaymentsApiCancelPaymentByIdempotencyKeyPOST /v2/payments/cancel
PaymentsApiCompletePaymentPOST /v2/payments/{payment_id}/complete
PaymentsApiCreatePaymentPOST /v2/payments
PaymentsApiGetPaymentGET /v2/payments/{payment_id}
PaymentsApiListPaymentsGET /v2/payments
RefundsApiGetPaymentRefundGET /v2/refunds/{refund_id}
RefundsApiListPaymentRefundsGET /v2/refunds
RefundsApiRefundPaymentPOST /v2/refunds
ReportingApiListAdditionalRecipientReceivableRefundsGET /v2/locations/{location_id}/additional-recipient-receivable-refunds
ReportingApiListAdditionalRecipientReceivablesGET /v2/locations/{location_id}/additional-recipient-receivables
TransactionsApiCaptureTransactionPOST /v2/locations/{location_id}/transactions/{transaction_id}/capture
TransactionsApiChargePOST /v2/locations/{location_id}/transactions
TransactionsApiCreateRefundPOST /v2/locations/{location_id}/transactions/{transaction_id}/refund
TransactionsApiListRefundsGET /v2/locations/{location_id}/refunds
TransactionsApiListTransactionsGET /v2/locations/{location_id}/transactions
TransactionsApiRetrieveTransactionGET /v2/locations/{location_id}/transactions/{transaction_id}
TransactionsApiVoidTransactionPOST /v2/locations/{location_id}/transactions/{transaction_id}/void
V1EmployeesApiCreateEmployeePOST /v1/me/employees
V1EmployeesApiCreateEmployeeRolePOST /v1/me/roles
V1EmployeesApiCreateTimecardPOST /v1/me/timecards
V1EmployeesApiDeleteTimecardDELETE /v1/me/timecards/{timecard_id}
V1EmployeesApiListCashDrawerShiftsGET /v1/{location_id}/cash-drawer-shifts
V1EmployeesApiListEmployeeRolesGET /v1/me/roles
V1EmployeesApiListEmployeesGET /v1/me/employees
V1EmployeesApiListTimecardEventsGET /v1/me/timecards/{timecard_id}/events
V1EmployeesApiListTimecardsGET /v1/me/timecards
V1EmployeesApiRetrieveCashDrawerShiftGET /v1/{location_id}/cash-drawer-shifts/{shift_id}
V1EmployeesApiRetrieveEmployeeGET /v1/me/employees/{employee_id}
V1EmployeesApiRetrieveEmployeeRoleGET /v1/me/roles/{role_id}
V1EmployeesApiRetrieveTimecardGET /v1/me/timecards/{timecard_id}
V1EmployeesApiUpdateEmployeePUT /v1/me/employees/{employee_id}
V1EmployeesApiUpdateEmployeeRolePUT /v1/me/roles/{role_id}
V1EmployeesApiUpdateTimecardPUT /v1/me/timecards/{timecard_id}
V1ItemsApiAdjustInventoryPOST /v1/{location_id}/inventory/{variation_id}
V1ItemsApiApplyFeePUT /v1/{location_id}/items/{item_id}/fees/{fee_id}
V1ItemsApiApplyModifierListPUT /v1/{location_id}/items/{item_id}/modifier-lists/{modifier_list_id}
V1ItemsApiCreateCategoryPOST /v1/{location_id}/categories
V1ItemsApiCreateDiscountPOST /v1/{location_id}/discounts
V1ItemsApiCreateFeePOST /v1/{location_id}/fees
V1ItemsApiCreateItemPOST /v1/{location_id}/items
V1ItemsApiCreateModifierListPOST /v1/{location_id}/modifier-lists
V1ItemsApiCreateModifierOptionPOST /v1/{location_id}/modifier-lists/{modifier_list_id}/modifier-options
V1ItemsApiCreatePagePOST /v1/{location_id}/pages
V1ItemsApiCreateVariationPOST /v1/{location_id}/items/{item_id}/variations
V1ItemsApiDeleteCategoryDELETE /v1/{location_id}/categories/{category_id}
V1ItemsApiDeleteDiscountDELETE /v1/{location_id}/discounts/{discount_id}
V1ItemsApiDeleteFeeDELETE /v1/{location_id}/fees/{fee_id}
V1ItemsApiDeleteItemDELETE /v1/{location_id}/items/{item_id}
V1ItemsApiDeleteModifierListDELETE /v1/{location_id}/modifier-lists/{modifier_list_id}
V1ItemsApiDeleteModifierOptionDELETE /v1/{location_id}/modifier-lists/{modifier_list_id}/modifier-options/{modifier_option_id}
V1ItemsApiDeletePageDELETE /v1/{location_id}/pages/{page_id}
V1ItemsApiDeletePageCellDELETE /v1/{location_id}/pages/{page_id}/cells
V1ItemsApiDeleteVariationDELETE /v1/{location_id}/items/{item_id}/variations/{variation_id}
V1ItemsApiListCategoriesGET /v1/{location_id}/categories
V1ItemsApiListDiscountsGET /v1/{location_id}/discounts
V1ItemsApiListFeesGET /v1/{location_id}/fees
V1ItemsApiListInventoryGET /v1/{location_id}/inventory
V1ItemsApiListItemsGET /v1/{location_id}/items
V1ItemsApiListModifierListsGET /v1/{location_id}/modifier-lists
V1ItemsApiListPagesGET /v1/{location_id}/pages
V1ItemsApiRemoveFeeDELETE /v1/{location_id}/items/{item_id}/fees/{fee_id}
V1ItemsApiRemoveModifierListDELETE /v1/{location_id}/items/{item_id}/modifier-lists/{modifier_list_id}
V1ItemsApiRetrieveItemGET /v1/{location_id}/items/{item_id}
V1ItemsApiRetrieveModifierListGET /v1/{location_id}/modifier-lists/{modifier_list_id}
V1ItemsApiUpdateCategoryPUT /v1/{location_id}/categories/{category_id}
V1ItemsApiUpdateDiscountPUT /v1/{location_id}/discounts/{discount_id}
V1ItemsApiUpdateFeePUT /v1/{location_id}/fees/{fee_id}
V1ItemsApiUpdateItemPUT /v1/{location_id}/items/{item_id}
V1ItemsApiUpdateModifierListPUT /v1/{location_id}/modifier-lists/{modifier_list_id}
V1ItemsApiUpdateModifierOptionPUT /v1/{location_id}/modifier-lists/{modifier_list_id}/modifier-options/{modifier_option_id}
V1ItemsApiUpdatePagePUT /v1/{location_id}/pages/{page_id}
V1ItemsApiUpdatePageCellPUT /v1/{location_id}/pages/{page_id}/cells
V1ItemsApiUpdateVariationPUT /v1/{location_id}/items/{item_id}/variations/{variation_id}
V1LocationsApiListLocationsGET /v1/me/locations
V1LocationsApiRetrieveBusinessGET /v1/me
V1TransactionsApiCreateRefundPOST /v1/{location_id}/refunds
V1TransactionsApiListBankAccountsGET /v1/{location_id}/bank-accounts
V1TransactionsApiListOrdersGET /v1/{location_id}/orders
V1TransactionsApiListPaymentsGET /v1/{location_id}/payments
V1TransactionsApiListRefundsGET /v1/{location_id}/refunds
V1TransactionsApiListSettlementsGET /v1/{location_id}/settlements
V1TransactionsApiRetrieveBankAccountGET /v1/{location_id}/bank-accounts/{bank_account_id}
V1TransactionsApiRetrieveOrderGET /v1/{location_id}/orders/{order_id}
V1TransactionsApiRetrievePaymentGET /v1/{location_id}/payments/{payment_id}
V1TransactionsApiRetrieveSettlementGET /v1/{location_id}/settlements/{settlement_id}
V1TransactionsApiUpdateOrderPUT /v1/{location_id}/orders/{order_id}

Documentation for Models

Documentation for Authorization

oauth2

  • Type: OAuth
  • Flow: accessCode
  • Authorization URL: https://connect.squareup.com/oauth2/authorize
  • Scopes:
    • BANK_ACCOUNTS_READ: HTTP Method: `GET` Grants read access to bank account information associated with the targeted Square account. For example, to call the Connect v1 ListBankAccounts endpoint.
    • CUSTOMERS_READ: HTTP Method: `GET` Grants read access to customer information. For example, to call the ListCustomers endpoint.
    • CUSTOMERS_WRITE: HTTP Method: `POST`, `PUT`, `DELETE` Grants write access to customer information. For example, to create and update customer profiles.
    • EMPLOYEES_READ: HTTP Method: `GET` Grants read access to employee profile information. For example, to call the Connect v1 Employees API.
    • EMPLOYEES_WRITE: HTTP Method: `POST`, `PUT`, `DELETE` Grants write access to employee profile information. For example, to create and modify employee profiles.
    • INVENTORY_READ: HTTP Method: `GET` Grants read access to inventory information. For example, to call the RetrieveInventoryCount endpoint.
    • INVENTORY_WRITE: HTTP Method: `POST`, `PUT`, `DELETE` Grants write access to inventory information. For example, to call the BatchChangeInventory endpoint.
    • ITEMS_READ: HTTP Method: `GET` Grants read access to business and location information. For example, to obtain a location ID for subsequent activity.
    • ITEMS_WRITE: HTTP Method: `POST`, `PUT`, `DELETE` Grants write access to product catalog information. For example, to modify or add to a product catalog.
    • MERCHANT_PROFILE_READ: HTTP Method: `GET` Grants read access to business and location information. For example, to obtain a location ID for subsequent activity.
    • ORDERS_READ: HTTP Method: `GET` Grants read access to order information. For example, to call the BatchRetrieveOrders endpoint.
    • ORDERS_WRITE: HTTP Method: `POST`, `PUT`, `DELETE` Grants write access to order information. For example, to call the CreateCheckout endpoint.
    • PAYMENTS_READ: HTTP Method: `GET` Grants read access to transaction and refund information. For example, to call the RetrieveTransaction endpoint.
    • PAYMENTS_WRITE: HTTP Method: `POST`, `PUT`, `DELETE` Grants write access to transaction and refunds information. For example, to process payments with the Payments or Checkout API.
    • PAYMENTS_WRITE_ADDITIONAL_RECIPIENTS: HTTP Method: `POST`, `PUT`, `DELETE` Allow third party applications to deduct a portion of each transaction amount. Required to use multiparty transaction functionality with the Payments API.
    • PAYMENTS_WRITE_IN_PERSON: HTTP Method: `POST`, `PUT`, `DELETE` Grants write access to payments and refunds information. For example, to process in-person payments.
    • SETTLEMENTS_READ: HTTP Method: `GET` Grants read access to settlement (deposit) information. For example, to call the Connect v1 ListSettlements endpoint.
    • TIMECARDS_READ: HTTP Method: `GET` Grants read access to employee timecard information. For example, to call the Connect v2 SearchShifts endpoint.
    • TIMECARDS_WRITE: HTTP Method: `POST`, `PUT`, `DELETE` Grants write access to employee shift information. For example, to create and modify employee shifts.
    • TIMECARDS_SETTINGS_READ: HTTP Method: `GET` Grants read access to employee timecard settings information. For example, to call the GetBreakType endpoint.
    • TIMECARDS_SETTINGS_WRITE: HTTP Method: `POST`, `PUT`, `DELETE` Grants write access to employee timecard settings information. For example, to call the UpdateBreakType endpoint.

oauth2ClientSecret

  • Type: API key
  • API key parameter name: Authorization
  • Location: HTTP header

Pagination of V1 Endpoints

V1 Endpoints return pagination information via HTTP headers. In order to obtain response headers and extract the batch_token parameter you will need to follow the following steps:

  1. Use the full information endpoint methods of each API to get the ApiResponse object. They are named as their simple counterpart with a WithHttpInfo suffix. Hence ListEmployeeRoles would be called ListEmployeeRolesWithHttpInfo. This method returns an ApiResponse<List<V1EmployeeRole>> object.

  2. Use string batchToken = response.BatchToken to get the token and proceed to get the following page if a token is present.

Example

using System;
using System.Diagnostics;
using Square.Connect.Api;
using Square.Connect.Client;
using Square.Connect.Model;

namespace Example
{
    public class ListEmployeeRolesExample
    {
        public void main()
        {
            // Configure OAuth2 access token for authorization: oauth2
            Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";

            var apiInstance = new V1EmployeesApi();
            var order = order_example;  // string | The order in which employees are listed in the response, based on their created_at field.Default value: ASC  (optional)
            var limit = 56;  // int? | The maximum integer number of employee entities to return in a single response. Default 100, maximum 200. (optional)
            string batchToken = null;

            try
            {
                do {
                    // Provides summary information for all of a business's employee roles.
                    ApiResponse<List<V1EmployeeRole>> response = apiInstance.ListEmployeeRolesWithHttpInfo(order, limit, batchToken);
                    batchToken = response.BatchToken
                    Debug.WriteLine(response.Data);
                } while (batchToken != null);
            }
            catch (Exception e)
            {
                Debug.Print("Exception when calling V1EmployeesApi.ListEmployeeRolesWithHttpInfo: " + e.Message );
            }
        }
    }
}

Contributing

Send bug reports, feature requests, and code contributions to the API specifications repository, as this repository contains only the generated SDK code.

License

Copyright 2017 Square, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.