# How to replace layoutSections via page API

**URL:** <https://community.hubspot.com/t/how-to-replace-layoutsections-via-page-api/98740>\
**Category:** APIs & Integrations\
**Tags:** timeline-and-extensions-apis\
**Created:** [January 26, 2024, 11:01am UTC](https://community.hubspot.com/t/how-to-replace-layoutsections-via-page-api/98740 "2024-01-26T11:01:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TDwebdev](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tdwebdev/32/78032_2.png) [@TDwebdev](https://community.hubspot.com/u/TDwebdev)\
**Post date:** [January 26, 2024, 11:01am UTC](https://community.hubspot.com/t/how-to-replace-layoutsections-via-page-api/98740/1 "2024-01-26T11:01:28Z")

</div>

I cant replace layoutSections of page via API. Error: errorType":“INVALID\_JSON\_VALUE”,“message”:"Unable to set value for layoutSections \> dnd\_area \> params on page from JSON

Code:

test = array(“layoutSections” =\> $response\_array[‘layoutSections’]);

$datas = json\_encode($test , JSON\_UNESCAPED\_SLASHES);

// The URL for the PATCH request

$url = ‘[https://api.hubapi.com/cms/v3/pages/site-pages/](https://api.hubapi.com/cms/v3/pages/site-pages/)’ . $page\_id;

// Initialize cURL session

$ch = curl\_init($url);

// Set cURL options

curl\_setopt($ch, CURLOPT\_CUSTOMREQUEST, ‘PATCH’);

curl\_setopt($ch, CURLOPT\_RETURNTRANSFER, true);

curl\_setopt($ch, CURLOPT\_HTTPHEADER, array(

```
'Authorization: Bearer ' . $bearer\_token,

'Content-Type: application/json'

```

));

curl\_setopt($ch, CURLOPT\_POSTFIELDS, $datas);

// Execute cURL session and fetch response

$response = curl\_exec($ch);

// Check for errors

if (curl\_errno($ch)) {

```
echo 'Error:' . curl\_error($ch);

```

} else {

```
// Print response for debugging

echo $response;

```

}

// Close cURL session

curl\_close($ch);

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [January 26, 2024, 7:17pm UTC](https://community.hubspot.com/t/how-to-replace-layoutsections-via-page-api/98740/2 "2024-01-26T19:17:55Z")

</div>

Hi, @TDwebdev! I hope you’ve been great.

A few questions to help get us started:

- have you tried to print out `$datas` before the cURL request and verify that the JSON looks correct?
- have you tried using Postman to manually send the PATCH request with your JSON to see if the issue is with the JSON or the way the PHP code is handling it?
- as a simple test, have you tried removing `JSON_UNESCAPED_SLASHES` to see if that has any effect? I don’t think it would, but it might be a simple thing to rule out as an issue

Thanks for the additional information! — Jaycee

---

<div class="post-metadata">

**Author:** ![PDeT](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@PDeT](https://community.hubspot.com/u/PDeT)\
**Post date:** [July 3, 2024, 1:30pm UTC](https://community.hubspot.com/t/how-to-replace-layoutsections-via-page-api/98740/3 "2024-07-03T13:30:03Z")

</div>

Bumping into the same issue. Some observations:

- fetching a blog via api (postman) and sending the output back to hubspot to create a new one, works (no validation errors)

- fetching the same blog via the php-hubspot-api, and sending it unmodified back to hubspot to create a new one: validation errors, layoutSections, widget\_containers etc give validation errors. The json has been validated as valid json. Ther error returned is “Cannot deserialize value of type `java.util.LinkedHashMap\<java.lang.String,com.hubspot.content.model.layout.LayoutSection\>` from Array value (token `JsonToken.START_ARRAY`)”

So it seems it is not a json validation error; but a problem at the endpoint to parse an empty array.

The issue comes from sending an empty array in stead of an empty object ([] vs {} in json) in my case, so make sure to check if you are sending an object for layoutSections… it think this is because layou sections are keyd with an internal name.
