Skip to content

CTA card cannot be imported as html with visibility settings intact #24588

@cathysarisky

Description

@cathysarisky

Issue Summary

I'm trying to create a new post with the Ghost Admin API. I have a CTA card, that should only be available to free members.
Here's the start of the html I'm passing in:
(removing the comment wrapping because otherwise github removes it upon publication, but it is wrapped like an html comment, honest!)
!--kg-gated-block:begin nonMember:false memberSegment:"status:free" --

`

        <div class="kg-cta-content">
            
            
                <div class="kg-cta-content-inner">
                
                    <div class="kg-cta-text">
                        <p><span style="white-space: pre-wrap;">Thanks for reading. Paying subscribers receive access to each article on Fridays. Free subscribers receive access on the following Monday. Want faster access? Upgrade now!</span></p>
                    </div>
                
                
                    <a href="#/portal/account/plans" class="kg-cta-button " style="background-color: #000000; color: #ffffff;">
                        Upgrade your plan
                    </a>
                    
                </div>
            
        </div>
    </div>

`
!--kg-gated-block:end--

(I got this HTML by inspecting what came from the Admin API so I'm pretty sure I've got it right!)

The CTA card is created correctly, based on my viewing in the editor, EXCEPT that all the visibility toggles are 'on', although they should not be.

Steps to Reproduce

Here's the function I'm using:
`async function createNewsletterDraft(html, dateRange, options = {}) {
const api = getAdminAPI();

const title = options.title || Newsletter - ${dateRange.after} to ${dateRange.before};
const tags = options.tags || ['#newsletter-draft'];

try {
let result;

  // Create new draft
  const post = {
    title: title,
    html: html,
    status: 'draft',
    tags: tags,
    custom_excerpt: `Newsletter covering ${dateRange.after} to ${dateRange.before}`
  };
  
  result = await api.posts.add(post, { source: 'html' });


return result;

} catch (error) {
console.error('Error creating newsletter draft:', error);
throw error;
}
}`

Ghost Version

latest / Ghost Pro

Node.js Version

Ghost Pro

How did you install Ghost?

Ghost Pro

Database type

MySQL 5.7

Browser & OS version

No response

Relevant log / error output

No errors thrown by my function. Just not getting the expected result.

Code of Conduct

  • I agree to be friendly and polite to people in this repository

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug[triage] something behaving unexpectedly

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions