Skip to content

migrate from Ahrefs/SpaceCat API key to Semrush/IMS session token auth - #22

Draft
habansal wants to merge 3 commits into
basecode:mainfrom
habansal:feat/migrate-ahrefs-to-semrush-ims-auth
Draft

migrate from Ahrefs/SpaceCat API key to Semrush/IMS session token auth#22
habansal wants to merge 3 commits into
basecode:mainfrom
habansal:feat/migrate-ahrefs-to-semrush-ims-auth

Conversation

@habansal

Copy link
Copy Markdown

Summary

  • Replace dead spacecat-sdk package with @adobe/mysticat-shared-seo-client (Semrush); remove spacecat-audit-worker imports that were never in package.json
  • Replace AhrefsAPIClient with SeoClient across all assessments (brokenBacklinks, brokenInternalLinks, canonical, PageProvider) — uses Semrush backlinks_pages+backlinks two-step approach matching audit-worker v1
  • Replace SPACECAT_API_KEY (x-api-key header) with SPACECAT_SESSION_TOKEN (Authorization: Bearer) across all SpaceCat API calls; replace SpaceCatSdk.getSite() with direct REST fetch to GET /sites/by-base-url/:base64url

New .env required

SPACECAT_SESSION_TOKEN=   # IMS JWT — copy from browser DevTools Authorization header after signing into SpaceCat
SEO_API_KEY=              # Semrush API key — from Vault
SEO_API_BASE_URL=https://api.semrush.com

Test plan

  • npm install completes without errors
  • npm run broken-backlinks <baseURL> returns Semrush-sourced results with source: semrush
  • npm run canonical <baseURL> fetches top pages from Semrush (log: "Fetching top N pages from Semrush")
  • npm run broken-internal-links <baseURL> fetches pages via Semrush
  • all-broken-backlinks-enabled.js, all-gsc-enabled.js, all-jsonld-enabled.js, enable-404.js authenticate via Bearer token without 401

🤖 Generated with Claude Code

- Replace dead spacecat-sdk package with @adobe/mysticat-shared-seo-client
- Replace AhrefsAPIClient with SeoClient (Semrush) across all assessments
- Replace SPACECAT_API_KEY (x-api-key header) with SPACECAT_SESSION_TOKEN
  (Authorization: Bearer) across all SpaceCat API calls
- Replace SpaceCatSdk.getSite() with direct REST fetch to /sites/by-base-url
- Update PageProvider to use seoClient.getTopPages(url, { limit }) signature
- Update brokenBacklinks to use SeoClient.getBrokenBacklinks two-step approach
- Update README setup instructions with new required env vars
- Update tests to reflect new SeoClient interface

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@habansal
habansal marked this pull request as draft August 19, 2026 08:41
habansal and others added 2 commits August 19, 2026 17:50
- Make SpaceCat lookup optional: warn and continue if site not found
  or token not set, rather than throwing
- Strip www. prefix before SpaceCat base-URL lookup to match stored format
- Fix sitemap index parsing passing object instead of URL string to fetch

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant