Skip to content

Updating site pages content - Hard or easy? #385

Open
@PascalKremp

Description

@PascalKremp
    public function getPage($objectId)
    {
        try {
            return $this->client->cms()->pages()->sitePagesApi()->getById($objectId);
        } catch (ApiException $e) {
            echo 'Exception when calling site_pages_api->get_by_id: ', $e->getMessage();
        }
    }

    public function updatePage($objectId, Page $page)
    {
        try {
            return $this->client->cms()->pages()->sitePagesApi()->update($objectId, $page);
        } catch (ApiException $e) {
            return $e->getResponseBody();
            //            echo 'Exception when calling site_pages_api->update: ', $e;
        }
    }
    $hubSpot = hubSpot();

    $objectId = 1234;

    $page = $hubSpot->getPage($objectId);
    $page->setSlug('test-123');
    $page->setHtmlTitle('test-123');

    return $hubSpot->updatePage($objectId, $page);

Maybe I am having a wrong idea on how to update a page. But doing this returns couple of errors.

One error is for example that translations key has empty array. If I unset the translations key value pair from $page it works. But I need to remove some more to make it working.

Some best practices on how to use API for this case (updating page content) would be appreciated, espacially for layoutSections.

$page->update() would be nice after making some changes with setters. Maybe this is already included and I don't know about it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions