API Explorer shows incorrect syntax for arrays via drush/cv
The problem I'm seeing is displayed in the attached screenshot. When you create an API call with API Explorer that requires the use of an array, API Explorer adds the array, JSON-encoded, to the argument list. However, neither drush nor cv (and I assume wp-cli) will parse the argument as an array. This has tripped up multiple folks on Stack Exchange (1, 2).
As answers to those SE questions point out, it IS possible to use drush/cv and encode arrays. Instead of:
cv api Contact.create contact_type="Individual" first_name="Jon" options={"match":"first_name"}
We could do:
echo '{"contact_type":"Individual","first_name":"Jon","options":{"match":"first_name"}}' | cv api Contact.create --in=json
There are three solutions of increasing effort, depending on how important folks think this is. I'm willing to do the first one, and someone else can do 2 or 3 if they feel it's important.
- Patch API Explorer so drush/cv/wp always show the (more complex)
echo foo | cv api bar.baz --in=json
syntax. - Patch API Explorer so drush/cv/wp show the more complex syntax when an array is present (I can do this if it's simple, I'd have to look).
- Patch drush/wp/cv to match API Explorer.