Skip to main content
The Laravel SDK ships attract:call: it calls one SDK method on your site and prints the answer as JSON. Use it to see what a method really answers before you write code against it, to check a key’s scopes, or to make a one-off change without writing a script.
Terminal

Find the method

attract:list names every method and its route.

Pass its arguments

name=value, with lists and objects as JSON.

Read the answer

Pretty JSON, ready for jq.
It runs in any Laravel app with fetchski/attract-cms-laravel installed and a site configured (Installation, Configuration). It uses the same key, so it can do exactly what your app can, and nothing more.

Find the method

Every method has a key: its accessor and its name, blogPosts.updateBlog. List them with attract:list:
Terminal
Narrow it to one accessor:
Terminal
Output
A misspelled accessor or key gets a suggestion (No resource blogPost: did you mean blogPosts?).
Every Laravel reference page opens with its method’s attract:call line, under Call it from the terminal: copy it, then change the values.

See a method’s arguments

--json prints each method’s entry: its arguments, their types and which are required. With jq:
Terminal
The method’s reference page says the same in words, with each argument’s rules.

Find an id first

Most methods take a document’s id. Every list has a …Pick twin that answers only the fields you name, for every document, so its ids are one short call away:
Terminal
Output
fields takes a comma list, or a JSON one ('fields=["title","slug"]'). More in Find an id.

Pass its arguments

Each argument is one name=value word after the key, named as the SDK names it:
Terminal
The value is read by the argument’s type: Quote a word that holds a space, JSON or a shell character. Single quotes around the whole name=value keep the shell out of it:
Terminal
Leave out an optional argument and it isn’t sent: the site’s default applies.
Nothing is sent, and the command says what to fix:
Output
The …All methods (blogPosts.listBlogsAll) walk every page of a list into models, which the command doesn’t offer: call the list method a page at a time (page=2), or its …Pick twin, which walks every page for the fields you name.

Writes ask first

A method that changes the site asks before it sends anything, naming the site:
Output
Answer yes to call it. In a script, or once you’re sure, add --force to skip the question:
Terminal
--force sends it at once. A write in published mode (the default) goes live: send aposMode=draft to change only the draft, and publish it from the CMS when it’s right (Drafts and locales).

Choose the site

With no option the command calls your default site (FETCHSKI_ATTRACT_SITE). When your app holds several, name one with --site=:
Terminal
The slug is one under sites in config/fetchski-attract.php, or one stored with attract:store-key when keys live in your database (Key in the database).

Read the answer

The answer is printed as pretty JSON, keyed as the site sends it (_id, not the SDK’s id):
Output
A call that works prints only its JSON, so it pipes straight into jq:
Terminal
The command exits 0 when the call worked and 1 when it didn’t, so a script can stop on a failure.

Save a file

The blog’s templates (blogPosts.getBlogMarkdownTemplate, blogPosts.getBlogMdxTemplate) answer a file. Add --save= to write it instead of printing its JSON: a folder (ending in /) keeps the name the site gives it, any other path is the file.
Terminal
Output
Missing folders are made, and an existing file is replaced. --save on a method that answers no file stops before calling the site, and says so.

When the site refuses

The site’s answer is passed on as it is, with the route:
Output
A 403 names the scope the key lacks (Required scopes); a 401 means the key itself was refused (Authentication).

Worked examples

The five newest posts, drafts included (a draft read needs the type’s write scope):
Terminal
One post by its id:
Terminal

Artisan commands

Every command the package adds, with its options.

Calling the API

The same calls in your app’s code.