Marketing skills for Claude Code and AI agents. CRO, copywriting, SEO, analytics, and growth engineering.
JavaScript agent-skillsai-agentsai-seoclaudeclaude-codeclaude-code-pluginclaude-skillscodexcontent-marketingconversion-rate-optimizationcopywritingcursoremail-marketinggenerative-engine-optimizationgrowth-marketingmarketingmarketing-automationsaas-marketingseoskill-md
fix(dataforseo): honor SERP market and language code overrides
Rudy Celekli6695ae7e52a2
diff --git a/tests/dataforseo-market.test.cjs b/tests/dataforseo-market.test.cjsnew file mode 100644index 0000000..c57b52d--- /dev/null+++ b/tests/dataforseo-market.test.cjs@@ -0,0 +1,37 @@+const { test } = require('node:test')+const assert = require('node:assert/strict')+const { spawnSync } = require('node:child_process')+const path = require('node:path')++const cli = path.resolve(__dirname, '../tools/clis/dataforseo.js')+function run(args, dry = false) {+ const source = `global.fetch = async (url, options) => ({ status: 200, text: async () => JSON.stringify({ url, method: options.method, body: JSON.parse(options.body) }) }); process.argv = ['node', ${JSON.stringify(cli)}, ...${JSON.stringify(args)}, ...( ${dry} ? ['--dry-run'] : [])]; require(${JSON.stringify(cli)});`+ const result = spawnSync(process.execPath, ['-e', source], {encoding: 'utf8', env: {...process.env, DATAFORSEO_LOGIN: 'fixture-login', DATAFORSEO_PASSWORD: 'fixture-password'}})+ assert.equal(result.status, 0, result.stderr)+ return JSON.parse(result.stdout)+}+test('SERP code flags select the requested market and language', () => {+ const result = run(['serp', 'google', '--keyword', 'chaussures', '--location-code', '2250', '--language-code', 'fr'])+ assert.deepEqual(result.body, [{keyword: 'chaussures', location_code: 2250, language_code: 'fr'}])+})+test('codes take precedence over conflicting name flags without sending both', () => {+ const result = run(['serp', 'google', '--keyword', 'shoes', '--location', 'United States', '--location-code', '2250', '--language', 'English', '--language-code', 'fr'])+ assert.deepEqual(result.body, [{keyword: 'shoes', location_code: 2250, language_code: 'fr'}])+})+test('explicit names and defaults retain their existing contract', () => {+ assert.deepEqual(run(['serp','google','--keyword','shoes']).body, [{keyword:'shoes',location_name:'United States',language_name:'English'}])+ assert.deepEqual(run(['serp','google','--keyword','chaussures','--location','France','--language','French']).body, [{keyword:'chaussures',location_name:'France',language_name:'French'}])+})+test('invalid or missing location code is rejected before requesting a paid report', () => {+ for (const value of ['abc', '0', '1.5', '9007199254740993', undefined]) {+ const result = run(['serp','google','--keyword','shoes','--location-code', ...(value === undefined ? [] : [value])])+ assert.match(result.error || '', /location-code/)+ assert.equal(result.body, undefined)+ }+})+test('missing language code is rejected and dry run uses the same market with masked auth', () => {+ assert.match(run(['serp','google','--keyword','shoes','--language-code']).error || '', /language-code/)+ const result = run(['serp','google','--keyword','shoes','--location-code','2250','--language-code','fr'], true)+ assert.deepEqual(result.body, [{keyword:'shoes',location_code:2250,language_code:'fr'}])+ assert.equal(result.headers.Authorization, '***')+})diff --git a/tools/clis/dataforseo.js b/tools/clis/dataforseo.jsindex b4286ac..e763890 100755--- a/tools/clis/dataforseo.js+++ b/tools/clis/dataforseo.js@@ -68,11 +68,24 @@ async function main() {case 'google': {const keyword = args.keywordif (!keyword) { result = { error: '--keyword required' }; break }- result = await api('POST', '/serp/google/organic/live/regular', [{- keyword,- location_name: location,- language_name: language,- }])+ const task = { keyword }+ if (args['location-code'] !== undefined) {+ if (typeof args['location-code'] !== 'string' || !Number.isSafeInteger(locationCode) || locationCode <= 0) {+ result = { error: '--location-code must be a positive integer' }; break+ }+ task.location_code = locationCode+ } else {+ task.location_name = location+ }+ if (args['language-code'] !== undefined) {+ if (typeof args['language-code'] !== 'string' || !args['language-code'].trim()) {+ result = { error: '--language-code requires a language code' }; break+ }+ task.language_code = languageCode+ } else {+ task.language_name = language+ }+ result = await api('POST', '/serp/google/organic/live/regular', [task])break}case 'locations':diff --git a/tools/integrations/dataforseo.md b/tools/integrations/dataforseo.mdindex 4a27cee..90558f7 100644--- a/tools/integrations/dataforseo.md+++ b/tools/integrations/dataforseo.md@@ -163,3 +163,15 @@ Request bodies are always JSON arrays (even for single requests).- programmatic-seo- content-strategy- competitors++### CLI market selection++For `serp google`, `--location-code` and `--language-code` select API codes+instead of location/language names. Explicit codes take precedence over name+flags; omitted flags retain United States and English. Preview the paid request+with `--dry-run`:++```bash+node tools/clis/dataforseo.js serp google --keyword chaussures \+ --location-code 2250 --language-code fr --dry-run+```