Mobile Authorization API: Code Cookbook

Request a mobile authorization code on the command line

Request authorization tokens with a command line tool to initialize Square mobile solutions like Reader SDK.

PowerShell (Command Line)

Before you start
Permalink Get a link to this section

You will need the following information:

  • A valid access token. Square recommends testing with sandbox credentials whenever possible. See Square API Access Tokens for more information.

  • An active location ID. Copy a valid Developer Account location ID from the Locations setting page of your Square application in the Developer Dashboard, or set the dashboard to Sandbox Settings mode and then copy a sandbox location ID.

Generate a mobile authorization code
Permalink Get a link to this section

We recommend generating mobile authorization codes programmatically because they are short-lived and cannot be hardcoded and reused. But you may need to generate a mobile authorization code manually during development.

To generate a mobile authorization code manually:

  1. Open the Square Application Dashboard.

  2. Copy your Personal Access Token from the Credentials page.

  3. Copy an active Location ID from the Locations page.

  1. Paste the values into the following PowerShell command:

$authHeader = @{ Authorization = 'Bearer  {0}' -f "ACCESS_TOKEN" }
Invoke-RestMethod -Uri |
   -Method Post |
   -ContentType "application/json" |
   -Headers $authHeader |
   -Body '{"location_id":"YOUR_LOCATION_ID"}' 

You should get a response that looks like this:
  "authorization_code": "YOUR_MOBILE_AUTHORIZATION_CODE",
  "expires_at": "2018-05-11T02:05:07Z"