Square Connect Python SDK Technical Reference

August 15, 2019 ยท View on GitHub


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


Requirements

Make sure you have Python 2 >=2.7.9 or Python 3 >= 3.4

Installation & Usage

Option 1: pip install

If the python package is hosted on Github, you can install directly from Github

pip install git+https://github.com/square/connect-python-sdk.git

(you may need to run pip with root permission: sudo pip install git+https://github.com/square/connect-python-sdk.git)

Option 2: Setuptools

Install via Setuptools.

python setup.py install --user

(or sudo python setup.py install to install the package for all users)

Getting Started

Please follow the installation procedure:

Then import the package:

import squareconnect

Retrieve your location IDs

from __future__ import print_function

import squareconnect
from squareconnect.rest import ApiException
from squareconnect.apis.locations_api import LocationsApi

# create an instance of the Location API class
api_instance = LocationsApi()
# setup authorization
api_instance.api_client.configuration.access_token = 'YOUR_ACCESS_TOKEN'

try:
    # ListLocations
    api_response = api_instance.list_locations()
    print (api_response.locations)
except ApiException as e:
    print ('Exception when calling LocationApi->list_locations: %s\n' % e)

Charge the card nonce



NOTE: The Transactions API is deprecated as of 2019-08-15. To process payments with the new Payments API you must migrate to the new Square Python SDK.


from __future__ import print_function
import uuid

import squareconnect
from squareconnect.rest import ApiException
from squareconnect.apis.transactions_api import TransactionsApi

# create an instance of the Transaction API class
api_instance = TransactionApi()
# setup authorization
api_instance.api_client.configuration.access_token = 'YOUR_ACCESS_TOKEN'

location_id = 'YOUR_LOCATION_ID'
nonce = 'YOUR_NONCE'

try:
    # Charge
    idempotency_key = str(uuid.uuid1())
    amount = {'amount': 100, 'currency': 'USD'}
    body = {'idempotency_key': idempotency_key, 'card_nonce': nonce, 'amount_money': amount}
    api_response = api_instance.charge(location_id, body)
    print (api_response.transaction)
except ApiException as e:
    print ('Exception when calling TransactionApi->charge: %s\n' % e)

Documentation for API Endpoints

All URIs are relative to Square Connect Documentation

ClassMethodHTTP request
ApplePayApiregister_domainPOST /v2/apple-pay/domains
CatalogApibatch_delete_catalog_objectsPOST /v2/catalog/batch-delete
CatalogApibatch_retrieve_catalog_objectsPOST /v2/catalog/batch-retrieve
CatalogApibatch_upsert_catalog_objectsPOST /v2/catalog/batch-upsert
CatalogApicatalog_infoGET /v2/catalog/info
CatalogApidelete_catalog_objectDELETE /v2/catalog/object/{object_id}
CatalogApilist_catalogGET /v2/catalog/list
CatalogApiretrieve_catalog_objectGET /v2/catalog/object/{object_id}
CatalogApisearch_catalog_objectsPOST /v2/catalog/search
CatalogApiupdate_item_modifier_listsPOST /v2/catalog/update-item-modifier-lists
CatalogApiupdate_item_taxesPOST /v2/catalog/update-item-taxes
CatalogApiupsert_catalog_objectPOST /v2/catalog/object
CheckoutApicreate_checkoutPOST /v2/locations/{location_id}/checkouts
CustomersApicreate_customerPOST /v2/customers
CustomersApicreate_customer_cardPOST /v2/customers/{customer_id}/cards
CustomersApidelete_customerDELETE /v2/customers/{customer_id}
CustomersApidelete_customer_cardDELETE /v2/customers/{customer_id}/cards/{card_id}
CustomersApilist_customersGET /v2/customers
CustomersApiretrieve_customerGET /v2/customers/{customer_id}
CustomersApisearch_customersPOST /v2/customers/search
CustomersApiupdate_customerPUT /v2/customers/{customer_id}
EmployeesApilist_employeesGET /v2/employees
EmployeesApiretrieve_employeeGET /v2/employees/{id}
InventoryApibatch_change_inventoryPOST /v2/inventory/batch-change
InventoryApibatch_retrieve_inventory_changesPOST /v2/inventory/batch-retrieve-changes
InventoryApibatch_retrieve_inventory_countsPOST /v2/inventory/batch-retrieve-counts
InventoryApiretrieve_inventory_adjustmentGET /v2/inventory/adjustment/{adjustment_id}
InventoryApiretrieve_inventory_changesGET /v2/inventory/{catalog_object_id}/changes
InventoryApiretrieve_inventory_countGET /v2/inventory/{catalog_object_id}
InventoryApiretrieve_inventory_physical_countGET /v2/inventory/physical-count/{physical_count_id}
LaborApicreate_break_typePOST /v2/labor/break-types
LaborApicreate_shiftPOST /v2/labor/shifts
LaborApidelete_break_typeDELETE /v2/labor/break-types/{id}
LaborApidelete_shiftDELETE /v2/labor/shifts/{id}
LaborApiget_break_typeGET /v2/labor/break-types/{id}
LaborApiget_employee_wageGET /v2/labor/employee-wages/{id}
LaborApiget_shiftGET /v2/labor/shifts/{id}
LaborApilist_break_typesGET /v2/labor/break-types
LaborApilist_employee_wagesGET /v2/labor/employee-wages
LaborApilist_workweek_configsGET /v2/labor/workweek-configs
LaborApisearch_shiftsPOST /v2/labor/shifts/search
LaborApiupdate_break_typePUT /v2/labor/break-types/{id}
LaborApiupdate_shiftPUT /v2/labor/shifts/{id}
LaborApiupdate_workweek_configPUT /v2/labor/workweek-configs/{id}
LocationsApilist_locationsGET /v2/locations
MobileAuthorizationApicreate_mobile_authorization_codePOST /mobile/authorization-code
OAuthApiobtain_tokenPOST /oauth2/token
OAuthApirenew_tokenPOST /oauth2/clients/{client_id}/access-token/renew
OAuthApirevoke_tokenPOST /oauth2/revoke
OrdersApibatch_retrieve_ordersPOST /v2/locations/{location_id}/orders/batch-retrieve
OrdersApicreate_orderPOST /v2/locations/{location_id}/orders
OrdersApisearch_ordersPOST /v2/orders/search
ReportingApilist_additional_recipient_receivable_refundsGET /v2/locations/{location_id}/additional-recipient-receivable-refunds
ReportingApilist_additional_recipient_receivablesGET /v2/locations/{location_id}/additional-recipient-receivables
TransactionsApicapture_transactionPOST /v2/locations/{location_id}/transactions/{transaction_id}/capture
TransactionsApichargePOST /v2/locations/{location_id}/transactions
TransactionsApicreate_refundPOST /v2/locations/{location_id}/transactions/{transaction_id}/refund
TransactionsApilist_refundsGET /v2/locations/{location_id}/refunds
TransactionsApilist_transactionsGET /v2/locations/{location_id}/transactions
TransactionsApiretrieve_transactionGET /v2/locations/{location_id}/transactions/{transaction_id}
TransactionsApivoid_transactionPOST /v2/locations/{location_id}/transactions/{transaction_id}/void
V1EmployeesApicreate_employeePOST /v1/me/employees
V1EmployeesApicreate_employee_rolePOST /v1/me/roles
V1EmployeesApicreate_timecardPOST /v1/me/timecards
V1EmployeesApidelete_timecardDELETE /v1/me/timecards/{timecard_id}
V1EmployeesApilist_cash_drawer_shiftsGET /v1/{location_id}/cash-drawer-shifts
V1EmployeesApilist_employee_rolesGET /v1/me/roles
V1EmployeesApilist_employeesGET /v1/me/employees
V1EmployeesApilist_timecard_eventsGET /v1/me/timecards/{timecard_id}/events
V1EmployeesApilist_timecardsGET /v1/me/timecards
V1EmployeesApiretrieve_cash_drawer_shiftGET /v1/{location_id}/cash-drawer-shifts/{shift_id}
V1EmployeesApiretrieve_employeeGET /v1/me/employees/{employee_id}
V1EmployeesApiretrieve_employee_roleGET /v1/me/roles/{role_id}
V1EmployeesApiretrieve_timecardGET /v1/me/timecards/{timecard_id}
V1EmployeesApiupdate_employeePUT /v1/me/employees/{employee_id}
V1EmployeesApiupdate_employee_rolePUT /v1/me/roles/{role_id}
V1EmployeesApiupdate_timecardPUT /v1/me/timecards/{timecard_id}
V1ItemsApiadjust_inventoryPOST /v1/{location_id}/inventory/{variation_id}
V1ItemsApiapply_feePUT /v1/{location_id}/items/{item_id}/fees/{fee_id}
V1ItemsApiapply_modifier_listPUT /v1/{location_id}/items/{item_id}/modifier-lists/{modifier_list_id}
V1ItemsApicreate_categoryPOST /v1/{location_id}/categories
V1ItemsApicreate_discountPOST /v1/{location_id}/discounts
V1ItemsApicreate_feePOST /v1/{location_id}/fees
V1ItemsApicreate_itemPOST /v1/{location_id}/items
V1ItemsApicreate_modifier_listPOST /v1/{location_id}/modifier-lists
V1ItemsApicreate_modifier_optionPOST /v1/{location_id}/modifier-lists/{modifier_list_id}/modifier-options
V1ItemsApicreate_pagePOST /v1/{location_id}/pages
V1ItemsApicreate_variationPOST /v1/{location_id}/items/{item_id}/variations
V1ItemsApidelete_categoryDELETE /v1/{location_id}/categories/{category_id}
V1ItemsApidelete_discountDELETE /v1/{location_id}/discounts/{discount_id}
V1ItemsApidelete_feeDELETE /v1/{location_id}/fees/{fee_id}
V1ItemsApidelete_itemDELETE /v1/{location_id}/items/{item_id}
V1ItemsApidelete_modifier_listDELETE /v1/{location_id}/modifier-lists/{modifier_list_id}
V1ItemsApidelete_modifier_optionDELETE /v1/{location_id}/modifier-lists/{modifier_list_id}/modifier-options/{modifier_option_id}
V1ItemsApidelete_pageDELETE /v1/{location_id}/pages/{page_id}
V1ItemsApidelete_page_cellDELETE /v1/{location_id}/pages/{page_id}/cells
V1ItemsApidelete_variationDELETE /v1/{location_id}/items/{item_id}/variations/{variation_id}
V1ItemsApilist_categoriesGET /v1/{location_id}/categories
V1ItemsApilist_discountsGET /v1/{location_id}/discounts
V1ItemsApilist_feesGET /v1/{location_id}/fees
V1ItemsApilist_inventoryGET /v1/{location_id}/inventory
V1ItemsApilist_itemsGET /v1/{location_id}/items
V1ItemsApilist_modifier_listsGET /v1/{location_id}/modifier-lists
V1ItemsApilist_pagesGET /v1/{location_id}/pages
V1ItemsApiremove_feeDELETE /v1/{location_id}/items/{item_id}/fees/{fee_id}
V1ItemsApiremove_modifier_listDELETE /v1/{location_id}/items/{item_id}/modifier-lists/{modifier_list_id}
V1ItemsApiretrieve_itemGET /v1/{location_id}/items/{item_id}
V1ItemsApiretrieve_modifier_listGET /v1/{location_id}/modifier-lists/{modifier_list_id}
V1ItemsApiupdate_categoryPUT /v1/{location_id}/categories/{category_id}
V1ItemsApiupdate_discountPUT /v1/{location_id}/discounts/{discount_id}
V1ItemsApiupdate_feePUT /v1/{location_id}/fees/{fee_id}
V1ItemsApiupdate_itemPUT /v1/{location_id}/items/{item_id}
V1ItemsApiupdate_modifier_listPUT /v1/{location_id}/modifier-lists/{modifier_list_id}
V1ItemsApiupdate_modifier_optionPUT /v1/{location_id}/modifier-lists/{modifier_list_id}/modifier-options/{modifier_option_id}
V1ItemsApiupdate_pagePUT /v1/{location_id}/pages/{page_id}
V1ItemsApiupdate_page_cellPUT /v1/{location_id}/pages/{page_id}/cells
V1ItemsApiupdate_variationPUT /v1/{location_id}/items/{item_id}/variations/{variation_id}
V1LocationsApilist_locationsGET /v1/me/locations
V1LocationsApiretrieve_businessGET /v1/me
V1TransactionsApicreate_refundPOST /v1/{location_id}/refunds
V1TransactionsApilist_bank_accountsGET /v1/{location_id}/bank-accounts
V1TransactionsApilist_ordersGET /v1/{location_id}/orders
V1TransactionsApilist_paymentsGET /v1/{location_id}/payments
V1TransactionsApilist_refundsGET /v1/{location_id}/refunds
V1TransactionsApilist_settlementsGET /v1/{location_id}/settlements
V1TransactionsApiretrieve_bank_accountGET /v1/{location_id}/bank-accounts/{bank_account_id}
V1TransactionsApiretrieve_orderGET /v1/{location_id}/orders/{order_id}
V1TransactionsApiretrieve_paymentGET /v1/{location_id}/payments/{payment_id}
V1TransactionsApiretrieve_settlementGET /v1/{location_id}/settlements/{settlement_id}
V1TransactionsApiupdate_orderPUT /v1/{location_id}/orders/{order_id}

Documentation For Models

Documentation For Enums

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 product catalog information. For example, to get an item or a list of items.
  • 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 Transactions 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 Transactions API.
  • PAYMENTS_WRITE_IN_PERSON: HTTP Method: POST, PUT, DELETE Grants write access to transaction 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 v1 ListTimecards endpoint.
  • TIMECARDS_WRITE: HTTP Method: POST, PUT, DELETE Grants write access to employee timecard information. For example, to create and modify timecards.
  • 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 get it from the response object after each call as follows:

Example

from __future__ import print_function

import squareconnect
from squareconnect.rest import ApiException
from squareconnect.apis.v1_employees_api import V1EmployeesApi

# create an instance of the V1 Employee API class
api_instance = V1EmployeesApi()
# setup authorization
api_instance.api_client.configuration.access_token = 'YOUR_ACCESS_TOKEN'
has_next_page = True
token = None

try:
    while has_next_page:
        # ListEmployeeRoles
        api_response = api_instance.list_employee_roles(batch_token=token)
        print (api_response.locations)

        token = api_instance.api_client.last_response.getbatch_token()
        has_next_page = token != None
except ApiException as e:
    print ('Exception when calling V1EmployeesApi->list_employee_roles: %s\n' % e)

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.