TryGhost / TryGhost/SDK

Creating a new member

Open
#489 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
134
Forks
87
Avg merge
12m
Merged PRs (30d)
25

Description

Issue Summary

When attempting to add a new member using the Ghost Admin API within an Astro project, I encounter a ValidationError indicating a validation failure for the "email" field, despite ensuring the email is correctly formatted and present in the request payload.

Steps to Reproduce
  1. Set up a Ghost Admin API instance with the necessary configuration (URL, key, version).
  2. Create an endpoint in an Astro project to handle member sign-up, which collects an email address from a form submission and attempts to add a new member using api.members.add.
  3. Submit a valid email address through the form to trigger the endpoint.

Expected result: The member should be added successfully, and a success response should be returned.

Actual result: The operation fails with a ValidationError, specifically mentioning a validation failure for the "email" field, despite the email being present and correctly formatted in the request.

Technical Details

Ghost Version: v5.47.0

This issue seems to suggest that there might be a problem with how the Ghost Admin API is handling or validating the email field in the request. I have verified that the email is correctly formatted and included in the request payload, suggesting the issue might lie within the API or its validation logic.

Code
export const POST = async ({ request }) => {
	const formData = await request.formData();
	const email = formData.get("email");
	if (
		!email ||
		!email.match(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/)
	) {
		return new Response(
			JSON.stringify({ message: "Invalid email address" }),
			{ status: 400 }
		);
	}

	try {
		const response = await api.members.add({
			members: [{ email }],
		});
		console.log("Member created:", response);
		return new Response(
			JSON.stringify({ message: "Member created successfully" }),
			{ status: 200 }
		);
	} catch (error) {
		console.error(error);
		return new Response(
			JSON.stringify({ message: "Error creating member" }),
			{ status: 500 }
		);
	}
};

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the api.members.add entry point and reproduce the request using the payload and Ghost version described in the issue. Trace the resulting email validation response through the SDK and compare it with the Admin API request format; done means identifying a project-side or SDK/API validation cause and confirming the corrected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.