JSON Input was invalid. Error Message: Syntax error

astegnerbsuastegnerbsu Member Posts: 4

Getting error attempting to POST using Python in VS19. The POST to refresh token works correctly. GETs using the retrieved access token also work. The header works for the GETs. The access token has expired.

r1 = requests.post(endpointCus, headers=_headers, data=payload1).json()

https://api.lightspeedapp.com/API/V3/Account/xxxxxx/Customer.json

{'Content-Type': 'application/json', 'Authorization': 'Bearer bd437db2fc80caf31d6aaafccc946b4de6782eeb'}

I structured the text for the POST to Customer.json with both options, along with using double quote instead of single. The single quotes work in the header. Get same results using the R-seriers Collection in Postman.

{'firstName': 'Adam', 'lastName': 'Stegnerson'}

{'Customer': {'firstName': 'Adam', 'lastName': 'Stegnerson'}}


Always get

{

  "httpCode": "400",

  "httpMessage": "Bad Request",

  "message": "JSON Input was invalid. Error Message: Syntax error",

  "errorClass": "InvalidArgumentException"

}

2 comments

  • Ali_MasoumieAli_Masoumie Moderator, Lightspeed Staff Posts: 380 moderator

    Hi,

    The following should work:

    {
       'Customer': {
          'firstName': 'Adam',
          'lastName': 'Stegnerson'
       }
    }
    
  • astegnerbsuastegnerbsu Member Posts: 4

    Nope, it didn't. Copied it from your message, inserted after '=' when setting the variable

    _headers = {

          'Content-Type': 'application/json',

          'Authorization': 'Bearer ' + _accessToken + ''

          }

    print(endpointCus)

    print(_headers)

    print(" ") 

    payload1 = {

            'Customer': {

             'firstName': 'Adam',

             'lastName': 'Stegnerson'

            }

          }


    r1 = requests.post(endpointCus, headers=_headers, data=payload1).json()

    print(json.dumps(r1, indent=4))

    generates: (with Account number that works with requests.get and fresh access token)


    https://api.lightspeedapp.com/API/V3/Account/xxxxxx/Customer.json

    {'Content-Type': 'application/json', 'Authorization': 'Bearer {Access Token}'}


    {

      "httpCode": "400",

      "httpMessage": "Bad Request",

      "message": "JSON Input was invalid. Error Message: Syntax error",

      "errorClass": "InvalidArgumentException"

    }

    done

    Press any key to continue . . .

Sign In or Register to comment.