# Square Node SDK Post Requests return error 'Expected "{" (line 1, character 1)'

**URL:** <https://developer.squareup.com/forums/t/square-node-sdk-post-requests-return-error-expected-line-1-character-1/3388>\
**Category:** Questions\
**Tags:** sdk, node-js\
**Created:** [September 7, 2021, 1:14pm UTC](https://developer.squareup.com/forums/t/square-node-sdk-post-requests-return-error-expected-line-1-character-1/3388 "2021-09-07T13:14:02Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jake-fryde](https://avatars.discourse-cdn.com/v4/letter/j/91b2a8/32.png) [@jake-fryde](https://developer.squareup.com/forums/u/jake-fryde)\
**Post date:** [September 7, 2021, 1:14pm UTC](https://developer.squareup.com/forums/t/square-node-sdk-post-requests-return-error-expected-line-1-character-1/3388/1 "2021-09-07T13:14:02Z")

</div>

Hello, I’ve been getting the following error since Sunday when using the Node SDK. It seems like this is only happening on requests which result in a PUT or POST request under the hood as calls like `listCards` or `listLocations` are working, however `searchTeamMembers` or `obtainToken` are throwing the following error:

```auto
STATUS 400

{
   code: 'BAD_REQUEST',
   detail: 'Expected "{" (line 1, character 1)',
   category: 'INVALID_REQUEST_ERROR'
}

```

An example of a call through the SDK which is currently failing:

```auto
client.teamApi.searchTeamMembers({})

```

Further notes:  
After checking the API logs I noticed that when the POST requests started failing the requests which the SDK was actually sending changed from an object to a string

Failed Request Example: (search catalog objects)

```auto
content-length: 42
content-type: application/json
square-version: 2021-08-18
accept: application/json
user-agent: Square-TypeScript-SDK/13.1.0

"{\"query\":{\"filter\":{}},\"limit\":25}"

```

Successful Request example from a few days ago:

```auto
User-Agent: Square-TypeScript-SDK/13.1.0
Accept: application/json
Content-Length: 198
Square-Version: 2021-08-18
Content-Type: application/json

 {
  "object_types": [
    "ITEM"
  ],
  "include_deleted_objects": false,
  "include_related_objects": false,
  "query": {
    "exact_query": {
      "attribute_name": "image_id",
      "attribute_value": "DX2PPNM7OTCQKVOM3RNYZEUX"
    }
  },
  "limit": 1
}

```

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [September 7, 2021, 6:08pm UTC](https://developer.squareup.com/forums/t/square-node-sdk-post-requests-return-error-expected-line-1-character-1/3388/2 "2021-09-07T18:08:24Z")

</div>

We haven’t been able to replicate this behavior. Would you mind providing the snippet of code that you are getting the error with?

---

<div class="post-metadata">

**Author:** ![jake-fryde](https://avatars.discourse-cdn.com/v4/letter/j/91b2a8/32.png) [@jake-fryde](https://developer.squareup.com/forums/u/jake-fryde)\
**Post date:** [September 7, 2021, 9:28pm UTC](https://developer.squareup.com/forums/t/square-node-sdk-post-requests-return-error-expected-line-1-character-1/3388/3 "2021-09-07T21:28:15Z")

</div>

I am fortunately no longer getting this error, but it was in every SDK call which resulted in a POST or PUT request (example `client.teamApi.searchTeamMembers({})`) . Think it may have been an internal dependency issue which was causing it - I updated my dependencies today and everything seems to be working. (Though doing the same thing yesterday was resulting in the same error, so I am a bit concerned of a potential repeat situation)

---

<div class="post-metadata">

**Author:** ![jake-fryde](https://avatars.discourse-cdn.com/v4/letter/j/91b2a8/32.png) [@jake-fryde](https://developer.squareup.com/forums/u/jake-fryde)\
**Post date:** [September 7, 2021, 9:53pm UTC](https://developer.squareup.com/forums/t/square-node-sdk-post-requests-return-error-expected-line-1-character-1/3388/4 "2021-09-07T21:53:41Z")

</div>

I take it back, it seems like this is still coming up when I run Square locally.

A call that’s failing me right now:

```auto
const {
  result: { accessToken, refreshToken },
} = await oAuthApi.obtainToken({
  grantType: 'refresh_token',
  clientId: process.env.SQUARE_APP_ID as string,
  clientSecret: process.env.SQUARE_APP_SECRET as string,
  refreshToken: prevRefreshToken,
});

```

And the full error message:

```auto
err => ApiError: Response status code was not ok: 400.
    at /Users/jakeengel/code/fryde/fryde-app/node_modules/@apimatic/core/lib/http/requestBuilder.js:360:23
    at DefaultRequestBuilder.<anonymous> (/Users/jakeengel/code/fryde/fryde-app/node_modules/@apimatic/core/lib/http/requestBuilder.js:172:50)
    at step (/Users/jakeengel/code/fryde/fryde-app/node_modules/tslib/tslib.js:143:27)
    at Object.next (/Users/jakeengel/code/fryde/fryde-app/node_modules/tslib/tslib.js:124:57)
    at fulfilled (/Users/jakeengel/code/fryde/fryde-app/node_modules/tslib/tslib.js:114:62)
    at processTicksAndRejections (internal/process/task_queues.js:95:5) {
  request: {
    method: 'POST',
    url: 'https://connect.squareupsandbox.com/oauth2/token',
    headers: {
      'user-agent': 'Square-TypeScript-SDK/13.1.0',
      'content-type': 'application/json',
      'Square-Version': '2021-08-18',
      accept: 'application/json'
    },
    body: {
      type: 'text',
      content: '{"client_id":"sandbox-sq0idb- ***","client_secret":"sandbox-*** ,"grant_type":"refresh_token","refresh_token":"***"}'
    }
  },
  statusCode: 400,
  headers: {
    'access-control-allow-headers': 'Content-Type, Authorization, Accept, X-Allow-Cookies, X-Block-Cookies',
    'access-control-expose-headers': 'Link',
    'content-type': 'application/json',
    vary: 'Origin, Accept-Encoding',
    'x-content-type-options': 'nosniff',
    'x-download-options': 'noopen',
    'x-frame-options': 'DENY',
    'x-permitted-cross-domain-policies': 'none',
    'x-request-id': 'Cgh0StVodOwmyBABGBAiCQjmk8Kh7O3yAg',
    'x-xss-protection': '1; mode=block',
    date: 'Tue, 07 Sep 2021 21:51:21 GMT',
    'content-length': '85',
    'strict-transport-security': 'max-age=631152000; includeSubDomains; preload',
    connection: 'close'
  },
  body: '{\n' +
    ' "message": "error parsing JSON; expected JSON object",\n' +
    ' "type": "bad_request"\n' +
    '}\n',
  result: [Object: null prototype] {
    message: 'error parsing JSON; expected JSON object',
    type: 'bad_request'
  },
  errors: [
    {
      category: 'V1_ERROR',
      code: 'bad_request',
      detail: 'error parsing JSON; expected JSON object',
      field: undefined
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [September 8, 2021, 3:01pm UTC](https://developer.squareup.com/forums/t/square-node-sdk-post-requests-return-error-expected-line-1-character-1/3388/5 "2021-09-08T15:01:07Z")

</div>

What are the dependencies you have in your `package.json`?

---

<div class="post-metadata">

**Author:** ![jake-fryde](https://avatars.discourse-cdn.com/v4/letter/j/91b2a8/32.png) [@jake-fryde](https://developer.squareup.com/forums/u/jake-fryde)\
**Post date:** [September 9, 2021, 12:11pm UTC](https://developer.squareup.com/forums/t/square-node-sdk-post-requests-return-error-expected-line-1-character-1/3388/6 "2021-09-09T12:11:56Z")

</div>

```auto
"dependencies": {
    "@googlemaps/google-maps-services-js": "^3.1.16",
    "@sendgrid/mail": "^7.4.6",
    "@slack/web-api": "^6.3.0",
    "apollo-server-express": "^3.3.0",
    "aws-sdk": "^2.981.0",
    "axios": "^0.21.4",
    "bcryptjs": "^2.4.3",
    "class-validator": "^0.13.1",
    "colors": "^1.4.0",
    "date-fns": "^2.23.0",
    "date-fns-tz": "^1.1.4",
    "express": "^4.17.1",
    "generate-password": "^1.6.1",
    "google-auth-library": "^7.8.0",
    "graphql": "^15.5.2",
    "graphql-type-json": "^0.3.2",
    "jimp": "^0.16.1",
    "jsonwebtoken": "^8.5.1",
    "pluralize": "^8.0.0",
    "qrcode": "^1.4.4",
    "sqs-consumer": "^5.6.0",
    "square": "13.1.0",
    "twilio": "^3.67.1",
    "type-graphql": "^1.1.0",
    "typedi": "^0.8.0",
    "typeorm": "^0.2.37",
    "uuid": "^8.3.0"
  }

```

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [September 10, 2021, 10:10pm UTC](https://developer.squareup.com/forums/t/square-node-sdk-post-requests-return-error-expected-line-1-character-1/3388/7 "2021-09-10T22:10:32Z")

</div>

We created a test app with those dependencies explicitly, and we could not reproduce this issue. Is there anything else that your app is doing that may be causing this?

---

<div class="post-metadata">

**Author:** ![jake-fryde](https://avatars.discourse-cdn.com/v4/letter/j/91b2a8/32.png) [@jake-fryde](https://developer.squareup.com/forums/u/jake-fryde)\
**Post date:** [September 13, 2021, 3:09pm UTC](https://developer.squareup.com/forums/t/square-node-sdk-post-requests-return-error-expected-line-1-character-1/3388/8 "2021-09-13T15:09:55Z")

</div>

I am unable to replicate it anymore as well. Either way, I implemented a retry with axios whenever this fails in the future.

In terms of my setup, the only weird thing would be that this application runs in a lerna + yarn-workspaces monorepo

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [September 13, 2021, 4:18pm UTC](https://developer.squareup.com/forums/t/square-node-sdk-post-requests-return-error-expected-line-1-character-1/3388/9 "2021-09-13T16:18:48Z")

</div>

Okay, please let us know if you run into this again with any additional information. 🙂
