2
votes

The Square REST API docs state that I should get a list of my locations and then use a returned location code when I call the transactions endpoint (to charge a credit card). I am doing exactly this but the returned error says that the merchant has no location with the supplied ID.

I have tried this with and without the location_id in the JSON sent to the transactions endpoint, since it is a path variable. Same result. I have also seen on Square's API FAQ that the usual cause of a 404 not found is the card nonce being created wrong, but this response clearly says the location ID is not valid.

I have tested this with Postman and JSON and I can see that the location code is correct. Here are my calls and the responses:

This is a GET request:

https://connect.squareup.com/v2/locations

And here is the response:

{
"locations": [
{
  "id": "FPVPFZ4DXXXXX",
  "name": "MyCompany",
  "address": {
    "address_line_1": "123 Candy Lane",
    "address_line_2": "",
    "locality": "Smithfield",
    "administrative_district_level_1": "RI",
    "postal_code": "02917",
    "country": "US"
  },
  "timezone": "America/Los_Angeles",
  "capabilities": [
    "CREDIT_CARD_PROCESSING"
  ]
},
{
  "id": "4FHNAN1WXXXXX",
  "name": "MyCompany2",
  "address": {
    "address_line_1": "567 Smith Street",
    "address_line_2": "",
    "locality": "Greenville",
    "administrative_district_level_1": "RI",
    "postal_code": "02828-2910",
    "country": "US"
  },
  "timezone": "America/Los_Angeles",
  "capabilities": [
    "CREDIT_CARD_PROCESSING"
  ]
 }
 ]
 }

I modified the returned IDs a bit in the above example.

Next I make a call to charge a card to this uri:

https://connect.squareup.com/v2/locations/FPVPFZ4DXXXXX/transactions

With this body:

{  
"note":"",
"idempotency_key":"azsxdcfvrtrewsdf",
"location_id":"FPVPFZ4DXXXXX",
"shipping_address":{  
  "address_line_1":"123 My Street",
  "address_line_2":null,
  "locality":"Greenville",
  "administrative_district_level_1":"RI",
  "postal_code":"02828",
  "country":"US"
},
"billing_address":{  
  "address_line_1":"123 My Street",
  "address_line_2":null,
  "locality":"Greenville",
  "administrative_district_level_1":"RI",
  "postal_code":"02828",
  "country":"US"
},
"card_nonce":"CBASEPPW7fjdUHe-3jP6ZZ4kvE0gAQ",
"reference_id":"RT-12345678",
"amount_money":{  
  "amount":12500,
  "currency":"USD"
},
"delay_capture":true,
"buyer_email_address":"[email protected]",
"customer_id":"JIM"
}

And I get this response:

{
"errors": [
{
  "category": "INVALID_REQUEST_ERROR",
  "code": "NOT_FOUND",
  "detail": "This merchant does not have a location with the ID    `FPVPFZ4DXXXXX`.",
  "field": "location_id"
}
]
}

So the location ID matches exactly the ID returned by the locations endpoint.

Can someone familiar with this API help me out? Square's docs and support is sadly lacking.

1

1 Answers

3
votes

I think the issue here is that you have tried to use your sandbox credentials (sandbox-sq0idp-defoUOlu...) to charge against your production location FPVPFZXXXXX. If you call ListLocations with your sandbox credentials, you should get a different location that you can then do sandbox charges with.