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
Terminal
Output
No resource blogPost: did you mean blogPosts?).
See a method’s arguments
--json prints each method’s entry: its arguments, their types and which are required. With jq:
Terminal
Find an id first
Most methods take a document’sid. 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 onename=value word after the key, named as the SDK names it:
Terminal
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
When an argument is wrong
When an argument is wrong
Nothing is sent, and the command says what to fix:
Output
Walking every page
Walking every page
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
yes to call it. In a script, or once you’re sure, add --force to skip the question:
Terminal
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
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
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
--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
403 names the scope the key lacks (Required scopes); a 401 means the key itself was
refused (Authentication).
Worked examples
- A read
- A draft write
- A bulk job
- An upload
The five newest posts, drafts included (a draft read needs the type’s write scope):One post by its id:
Terminal
Terminal
Related
Artisan commands
Every command the package adds, with its options.
Calling the API
The same calls in your app’s code.