semrush cli

Save and track keyword selections

Pipe research results from Keyword Magic and Keyword Gap into Saved Keywords or Position Tracking.

Research commands output structured JSON. You can extract high-opportunity phrases with Unix tools such as jq and import them directly into Saved Keywords lists, Keyword Strategy Builder baskets, or Position Tracking campaigns.

1. Extract phrases from Keyword Magic

Keyword Magic rows place search phrases in the .data.keywords[].phrase field:

selected_phrases=$(semrush keyword-magic --keyword 'cloud storage' \
  --database us --page-size 10 --json |
  jq -ce '[.data.keywords[].phrase] | unique | select(length > 0)')

printf '%s\n' "$selected_phrases"

The jq -ce filter ensures that empty result sets produce a non-zero exit code, preventing subsequent write commands from receiving blank inputs.

2. Extract phrases from Keyword Gap

Keyword Gap compares two to five domains. Note that Gap rows store phrases under .data.keywords[].keyword rather than phrase:

gap_phrases=$(semrush keyword-gap \
  --domains '["example.com","competitor.com"]' \
  --database us --limit 10 --json |
  jq -ce '[.data.keywords[].keyword] | unique | select(length > 0)')

printf '%s\n' "$gap_phrases"

3. Save phrases to a Saved Keywords collection

Import the extracted JSON array into a target collection using its decimal string list_id:

semrush saved-keywords-import --list-id 123456 \
  --keywords "$selected_phrases" \
  --database us \
  --tags '["gap-opportunity"]' \
  --confirm

Verify that the phrases were imported:

semrush saved-keywords --list-id 123456 --limit 10 --json

4. Save phrases to Keyword Strategy Builder

To import phrases into a Keyword Strategy Builder basket instead, supply both numeric basket_id and owner_id:

semrush keyword-list-import --basket-id 456 --owner-id 123 \
  --keywords "$selected_phrases" \
  --database us \
  --confirm

5. Send phrases directly to Position Tracking

To monitor rankings for the extracted phrases, pass the JSON array to your tracking target using its composite campaign identifier (for example, 456_789):

semrush position-keywords-add --campaign-id 456_789 \
  --keywords "$selected_phrases" \
  --tags '["tracked-candidate"]' \
  --confirm

Adding keywords consumes your account tracking keyword allowance.

On this page