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)

To use the steps in this guide, you need the following information:

  • An active location ID. Copy a valid Developer Account location ID from the Production Mode Locations setting page of your Square application in the Developer Dashboard.

  • A valid access token. See Square API Access Tokens for more information.

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 https://connect.squareup.com/mobile/authorization-code |
   -Method Post |
   -ContentType "application/json" |
   -Headers $authHeader |
   -Body '{"location_id":"YOUR_LOCATION_ID"}' 

You should get a response that looks like this:

squareup.com/mobile/authorization-code
{
  "authorization_code": "YOUR_MOBILE_AUTHORIZATION_CODE",
  "expires_at": "2018-05-11T02:05:07Z"
}