Must be passed as a JSON-encoded array. Solution

ericabizericabiz Member Posts: 2

This one took me forever to figure out, and should be documented in the official API docs since they suggest to use cURL.


[ and ] are invalid characters in a URL. The cURL wrapper that languages like PHP use automatically and silently get rid of them. So when Lightspeed asks you to create a request like:

https://api.lightspeedapp.com/API/Account/xxxxxx/Customer/yyyy.json?load_relations=\["Contact"\]&Contact.email=!~,


This request is going to fail. Lightspeed will respond with 400 Bad Request "load_relations must be passed as a JSON encoded array."

The solution? Encode JUST the [ ] characters and remove the escape backslashes:

json?load_relations=%5B"Contact"%5D&Contact.email=!~,

This will fix the issue.

For some reason, this isn't documented anywhere. Lightspeed, please add this to your documentation. It would have saved me so much time today. (I finally found the solution here: https://groups.google.com/forum/#!topic/merchantos-api-developers/9CDhGkSSp7U -- in an obscure old mailing list post.)

Sign In or Register to comment.