Skip to content

Commit 30b457f

Browse files
committed
fix(syndication): use gql-beta.hashnode.com and hashnode-cli headers
1 parent ea04d6b commit 30b457f

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

‎apps/sanity/functions/syndicate-content/index.ts‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ export const handler = documentEventHandler<ContentDocument>(
397397
slug: `${data._type}-${slug}`,
398398
tags: hashnodeTags,
399399
...(hashnodeCoverImageUrl
400-
? { coverImageOptions: { coverImageURL: hashnodeCoverImageUrl } }
400+
? { coverImage: hashnodeCoverImageUrl }
401401
: {}),
402402
originalArticleURL: canonicalUrl,
403403
contentMarkdown: `Original: ${canonicalUrl}\n\n${youtubeEmbed}${contentMarkdown}`,
@@ -416,14 +416,16 @@ export const handler = documentEventHandler<ContentDocument>(
416416
existingSyndication?.externalId || data.hashnode || null;
417417

418418
let publishedPost: { id: string; slug?: string; url?: string } | null = null;
419+
const authHeader = token.startsWith("Bearer ") ? token : `Bearer ${token}`;
419420

420421
if (existingHashnodeSlug && !existingHashnodeSlug.startsWith("simulated-")) {
421422
// Lookup post ID from Hashnode
422-
const getPostRes = await fetch("https://gql.hashnode.com", {
423+
const getPostRes = await fetch("https://gql-beta.hashnode.com", {
423424
method: "POST",
424425
headers: {
425426
"Content-Type": "application/json",
426-
Authorization: token,
427+
Authorization: authHeader,
428+
"x-hashnode-client": "hashnode-cli",
427429
},
428430
body: JSON.stringify({
429431
operationName: "Publication",
@@ -445,11 +447,12 @@ export const handler = documentEventHandler<ContentDocument>(
445447
const updateInput = { ...articleInput };
446448
delete updateInput.slug; // slug cannot be updated
447449

448-
const updateRes = await fetch("https://gql.hashnode.com", {
450+
const updateRes = await fetch("https://gql-beta.hashnode.com", {
449451
method: "POST",
450452
headers: {
451453
"Content-Type": "application/json",
452-
Authorization: token,
454+
Authorization: authHeader,
455+
"x-hashnode-client": "hashnode-cli",
453456
},
454457
body: JSON.stringify({
455458
operationName: "updatePost",
@@ -479,11 +482,12 @@ export const handler = documentEventHandler<ContentDocument>(
479482

480483
if (!publishedPost) {
481484
// Create post mutation
482-
const publishRes = await fetch("https://gql.hashnode.com", {
485+
const publishRes = await fetch("https://gql-beta.hashnode.com", {
483486
method: "POST",
484487
headers: {
485488
"Content-Type": "application/json",
486-
Authorization: token,
489+
Authorization: authHeader,
490+
"x-hashnode-client": "hashnode-cli",
487491
},
488492
body: JSON.stringify({
489493
operationName: "publishPost",

‎scripts/run-syndicate-post.mjs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,19 @@ async function run() {
248248
publicationId,
249249
slug: `${doc._type}-${slug}`,
250250
tags: hashnodeTags,
251-
...(hashnodeCoverImageUrl ? { coverImageOptions: { coverImageURL: hashnodeCoverImageUrl } } : {}),
251+
...(hashnodeCoverImageUrl ? { coverImage: hashnodeCoverImageUrl } : {}),
252252
originalArticleURL: canonicalUrl,
253253
contentMarkdown: `Original: ${canonicalUrl}\n\n${youtubeEmbed}${contentMarkdown}`,
254254
};
255255

256256
try {
257-
const publishRes = await fetch("https://gql.hashnode.com", {
257+
const authHeader = hashnodeToken.startsWith("Bearer ") ? hashnodeToken : `Bearer ${hashnodeToken}`;
258+
const publishRes = await fetch("https://gql-beta.hashnode.com", {
258259
method: "POST",
259260
headers: {
260261
"Content-Type": "application/json",
261-
Authorization: hashnodeToken,
262+
Authorization: authHeader,
263+
"x-hashnode-client": "hashnode-cli",
262264
},
263265
body: JSON.stringify({
264266
operationName: "publishPost",

0 commit comments

Comments
 (0)