square / square-nodejs-sdk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ListLocationResponse Address definition does not correspond to result value

oranpere opened this issue · comments

under the docs the ListLocationResponse should return a location with an Address that holds the property:
'address_line_1' as such:

{
  "locations": [
    {
      "address": {
        "address_line_1": "123 Main St", 
....

The actual Address definition shows a property of :
addressLine1?: string;

However, this property is empty in real time and 'address_line_1' holds the data,

other camel case properties are mapped incorrectly as well

In the SDK, it should be the camelCase properties (see here: https://github.com/square/square-nodejs-sdk/blob/master/doc/models/address.md). The docs that show "address_line_1" say "(In JSON)" (so not the SDK model).

Basically, the actual API returns the data in under_score_notation (like "address_line_1"), but the Node JS SDK uses camelCasing in the models as it's more typical of Javascript.

Can you clarify what you mean that the camelCase "addressLine1" property is empty, and the other holds the data? If you're using the SDK model, there shouldn't be one or the other, there should be only one.

@StephenJosey thank you for taking the time to respond,

What is the pattern you suggest using if the SDK is in camelCase and the actual API result is in under_score_notation ?

What I've been expecting is that if I see in the SDK:
ApiResponse that contains camelCase properties, these properties would be populated.

And in this instance it is not the case as you mentioned above the API returns populated under_score_notation properties, and so I need to map them ?

I think maybe I'm misunderstanding here. The actual SDK model is always camelCase (it's an object, and the fields are camelCased). If you're solely using the SDK and not looking at the raw response, you shouldn't need to worry about the under_score_notation. If the API doesn't have a populated result for a field, I assume the camelCase field would be null. Can you share a concrete example?

To give you a concrete example tried running the simple example, however I've encoutnered another issue,

`import { ApiError, Client, Environment } from 'square'

 
// Create an instance of the API Client 
// and initialize it with the credentials 
// for the Square account whose assets you want to manage
const client = new Client({
  timeout:3000,
  environment: Environment.Sandbox,
  accessToken: process.env.SQUARE_ACCESS_TOKEN,
})
 
// Get an instance of the Square API you want call
const { locationsApi } = client

// Create wrapper async function 
const getLocations = async () => {
  // The try/catch statement needs to be called from within an asynchronous function
  try {
    // Call listLocations method to get all locations in this Square account
    let listLocationsResponse = await locationsApi.listLocations()

    // Get first location from list
    let firstLocation = listLocationsResponse.result.locations[0]

    console.log("Here is your first location: ", firstLocation)
  } catch (error) {
    if (error instanceof ApiError) {
      console.log("There was an error in your request: ", error.errors)
    } else {
      console.log("Unexpected Error: ", error)
    }
  }
}

// Invokes the async function
getLocations()`

and I'm getting: Error:

Could not parse body as JSON.
Cannot convert 40.714348249173156 to a BigInt

Hm, do you mind sharing your Square application id, and the location_id that you're attempting to print out? I copied/pasted the code as is, with my own access token, and it works correctly on my end.

What version of Node are you using? Are you doing anything extra to compensate for converting BigInts (extra libraries or anything)? I know there is this open issue as well: #24 just wondering if this is something you implemented.

removing the problematic location solved the issue