# Trouble setting locations to closed on all days

**URL:** <https://developer.squareup.com/forums/t/trouble-setting-locations-to-closed-on-all-days/9377>\
**Category:** Questions\
**Tags:** locations-api\
**Created:** [May 3, 2023, 4:51pm UTC](https://developer.squareup.com/forums/t/trouble-setting-locations-to-closed-on-all-days/9377 "2023-05-03T16:51:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![robkerr](https://avatars.discourse-cdn.com/v4/letter/r/a9a28c/32.png) [@robkerr](https://developer.squareup.com/forums/u/robkerr)\
**Post date:** [May 3, 2023, 4:51pm UTC](https://developer.squareup.com/forums/t/trouble-setting-locations-to-closed-on-all-days/9377/1 "2023-05-03T16:51:51Z")

</div>

I’m using the JavaScript updateLocation api to maintain open hours. This allows store managers to modify/close stores in the case of power outages etc.

I’m having trouble when the manager needs to close the store completely (a food truck in winter, a power outage occurs).

If I send an empty array of `businessHours`, I get a nice error, which seems to want to clarify what I’m supposed to do to close the store completely (pass null):

But I can’t get it to work. Here’s what I initially guessed to do (empty array of days):

```auto
const payload = {
	location: {
		businessHours: []
	}
}
const updateResponse = await API.locations.updateLocation("ABCDEFGHIJ", payload)

This throws an error, and the response message is trying to be helpful: "Unspecified business hour periods. Clear business hours by setting the top-level field to null."

```

It’s unclear what “top-level field” is referring to, but I’m taking a guess it means businessHours(?)

So I send this instead:

```auto
const payload = {
	location: {
		businessHours: null
	}
}
const updateResponse = await API.locations.updateLocation("ABCDEFGHIJ", payload)

Response is now: "Given value: null\nType: 'object'\nExpected type: 'Optional<Lazy<Object<{periods}>>>'\nPath: location › businessHours"

```

I’m just not sure which field I’m supposed to set to null to clear business hours. I feel like I’m close but just missing some small detail. Any ideas?

---

<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:** [May 3, 2023, 6:42pm UTC](https://developer.squareup.com/forums/t/trouble-setting-locations-to-closed-on-all-days/9377/2 "2023-05-03T18:42:32Z")

</div>

Are you including the `X-Clear-Null` in the [header](https://developer.squareup.com/docs/locations-api#remove-location-fields) and setting it to `true`? If you want to set an existing field value to `null` , you must include the `X-Clear-Null` header. Otherwise, the request succeeds but the value is not cleared. For example:

```auto
  curl -X PUT \
-H 'Authorization: Bearer {ACCESS_TOKEN}' \
-H "Content-type: application/json" \
-H 'X-Clear-Null: true'
-d '{
   "location":{
      "business_hours": null
   }
}' \
'https://connect.squareupsandbox.com/v2/locations/{location_id}'

```

🙂

---

<div class="post-metadata">

**Author:** ![robkerr](https://avatars.discourse-cdn.com/v4/letter/r/a9a28c/32.png) [@robkerr](https://developer.squareup.com/forums/u/robkerr)\
**Post date:** [May 3, 2023, 7:28pm UTC](https://developer.squareup.com/forums/t/trouble-setting-locations-to-closed-on-all-days/9377/3 "2023-05-03T19:28:50Z")

</div>

Thanks, Bryan. That’s good to know about. I’m actually using your Node.js SDK to make these calls (not building http requests from scratch). Is there a way to make this same setting using the Saure Node.js SDK?

---

<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:** [May 3, 2023, 9:13pm UTC](https://developer.squareup.com/forums/t/trouble-setting-locations-to-closed-on-all-days/9377/4 "2023-05-03T21:13:31Z")

</div>

You will need to add it to the `client` as an additional header that’s passed in on an `UpdateLocation` call. 🙂

---

<div class="post-metadata">

**Author:** ![robkerr](https://avatars.discourse-cdn.com/v4/letter/r/a9a28c/32.png) [@robkerr](https://developer.squareup.com/forums/u/robkerr)\
**Post date:** [May 4, 2023, 5:00am UTC](https://developer.squareup.com/forums/t/trouble-setting-locations-to-closed-on-all-days/9377/5 "2023-05-04T05:00:17Z")

</div>

Thanks, Bryan!

If I make the call using curl as you did, it definitely works to set the header and set the location.businessHours to null. I can see that update in the square backend no problem.

I also figured out how to set the additionalHeaders in the node.js SDK, so thanks for the hint.

I still cannot make this work when using the Square node.js SDK. Complete repro code is below, and I think I see the problem:

– the Square node.js is typescript, and it’s enforcing that businessHours must be Optional\<Lazy\<Object\<{periods}\>\>\>  
– before the node SDK sends the HTTP request, it checks the payload, sees the null I assigned, and throws a type mismatch exception  
– while I did figure out how to set that extra header, it doesn’t matter since the square node.js SDK throws the exception before making the request.

I think this must be possible, but my lack of Typescript knowledge may be the blocker. I’m just at a loss how to assign null in my JS code when the expected data type is Optional\<Lazy\<Object\<{periods}\>\>\>. Any ideas?

Here’s a concise node.js SDK code example, and following is the exception thrown by the node.js SDK:

```auto
const config = {
	accessToken: "SQUARE_ACCESS_TOKEN",
	environment: "SQUARE_ENVIRONMENT",
	additionalHeaders: { 'X-Clear-Null': 'true' }
};
  
const square = new Client(config); 
const locationId = "SQUARE_LOCATION_ID"

try {
	var payload = {
	  location: {
	    businessHours: null
	  }
	}
	
	const updateResponse = await square.locationsApi.updateLocation(locationId, payload)

	return {
	  success: true,
	  message: "No exception thrown"
	}
	
} catch(error) {
	return {
	  success: false,
	  message: error.message
	};
}

```

Exception thrown (before HTTP request is attempted):

```auto
squareUpdateStoreHours Error: Argument for 'body' failed validation.
Expected value to be of type 'Optional<Lazy<Object<{periods}>>>' but found 'object'.

Given value: null
Type: 'object'\nExpected type: 'Optional<Lazy<Object<{periods}>>>'
Path: location › businessHours
    at new ArgumentsValidationError (/.../node_modules/@apimatic/core/lib/errors/argumentsValidationError.js:48:24)
        at DefaultRequestBuilder.prepareArgs (/.../node_modules/@apimatic/core/lib/http/validate.js:41:15)
            at LocationsApi._callee4$ (/.../node_modules/square/dist/square.cjs.development.js:11667:28)
                at tryCatch (/.../node_modules/square/dist/square.cjs.development.js:230:40)
                    at Generator.invoke [as _invoke] (/.../node_modules/square/dist/square.cjs.development.js:460:22)
                        at Generator.next (/.../node_modules/square/dist/square.cjs.development.js:285:21)
                            at asyncGeneratorStep (/.../node_modules/square/dist/square.cjs.development.js:13:24)
                                at _next (/.../node_modules/square/dist/square.cjs.development.js:35:9)
                                    at /.../node_modules/square/dist/square.cjs.development.js:42:7\n at new Promise (<anonymous>)
                                        at LocationsApi.<anonymous> (/.../node_modules/square/dist/square.cjs.development.js:31:12)
                                            at LocationsApi.updateLocation (/.../node_modules/square/dist/square.cjs.development.js:11685:30)
                                                at /.../square/square-stores.js:536:54
                                                    at newHandler (/Users/robkerr/.nvm/versions/node/v16.20.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:317:16)
                                                        at fixedLen (/.../node_modules/firebase-functions/lib/v1/providers/https.js:74:41)
                                                            at /.../node_modules/firebase-functions/lib/common/providers/https.js:438:32 {
                                                            	  errors: { body: [[Object] ] }
                                                            	  }"

```

---

<div class="post-metadata">

**Author:** ![emmawade](https://avatars.discourse-cdn.com/v4/letter/e/51bf81/32.png) [@emmawade](https://developer.squareup.com/forums/u/emmawade)\
**Post date:** [June 13, 2023, 7:54am UTC](https://developer.squareup.com/forums/t/trouble-setting-locations-to-closed-on-all-days/9377/6 "2023-06-13T07:54:11Z")

</div>

@[robkerr](https://followerbeast.com/instagram-vs-facebook/) Based on the error messages and the information provided, it seems that there might be some confusion regarding the correct syntax to clear the business hours using the JavaScript updateLocation API. Here’s a suggestion to try:

javascriptCopy code

```auto
const payload = {
  location: {
    businessHours: {
      periods: null
    }
  }
};

const updateResponse = await API.locations.updateLocation("ABCDEFGHIJ", payload);

```

In this example, instead of setting `businessHours` directly to `null`, you can set it as an object with a `periods` field set to `null`. This structure aligns with the expected type mentioned in the error message (`Optional<Lazy<Object<{periods}>>>'`). By setting `periods` to `null`, you indicate that there are no business hour periods specified.

Please note that the exact syntax and structure may depend on the specific API you are using and its documentation. It’s always recommended to refer to the API documentation or reach out to the API provider for further clarification on how to properly clear the business hours.
