How can I delete multiple records at once? Is it possible to select all, say "products" post_type, and delete it or it has to be one by one? (I'm not trying to clear all the records)
Algolia's dashboard is not designed to be a complete graphical interface on top of the API, it's mostly here for convenience, understanding and testing purposes, not complete management of the data.
As soon as you start being limited by the dashboard, you should probably write a small script to achieve what you're trying to do.
Fortunately, it's been designed to be as easy as possible.
With PHP, here's how it would look like:
First, let's create a small folder to hold the script.
mkdir /tmp/clear-algolia && cd /tmp/clear-algolia
If you don't have composer yet, you can simply install it in the current folder by launching the commands described here.
If you've just installed it and want to just use it just for this session:
alias composer=php composer.phar
Then install Algolia using composer:
composer require algolia/algoliasearch-client-php
Write a small script along those lines:
<?php
// removeSpecific.php
require __DIR__ . '/vendor/autoload.php';
$client = new \AlgoliaSearch\Client("YOUR_APP_ID", "YOUR_ADMIN_API_KEY");
$index = $client->initIndex('YOUR_INDEX');
$index->deleteByQuery('', [ 'filters' => 'post_type:products' ]);
?>
Then run it:
php removeSpecific.php
And you're good to go! Next time you want to do an operation on your index, you'll only have to change the last line of the script to achieve what you want.
You can use the REST API.
It can be easier or faster to do it with PostMan.
Here you can check a simple request: https://www.algolia.com/doc/rest-api/search/#delete-by
To first check what you are deleting, you can use:
curl --location --request POST 'https://[AplicationID]-
dsn.algolia.net/1/indexes/[IndexName]/query' \
--header 'X-Algolia-Application-Id: XXXXXXXXXXXX' \
--header 'X-Algolia-API-Key: XXXXXXXXXXXXXXXXXXXXXXXX' \
--header 'Content-Type: application/json' \
--data-raw '{
"params":"numericFilters=id<=9000"
}'
And to delete the records you can use:
curl --location --request POST
'https://[AplicationID].algolia.net/1/indexes/[IndexName]/deleteByQuery' \
--header 'X-Algolia-Application-Id: XXXXXXXXXXXX' \
--header 'X-Algolia-API-Key: XXXXXXXXXXXXXXXXXXXXX' \
--header 'Content-Type: application/json' \
--data-raw '{
"params":"numericFilters=id<=8000"
}'
The "params" should receive a Search Parameter, you can find a list here: https://www.algolia.com/doc/api-reference/search-api-parameters/
Related
I tried to create a tag using Github API. I made a POST request to /repos/:owner/:repo/git/tags, and I get this result:
HTTP/1.1 201 Created
But unfortunately no tag was created. The new tag simply does not exist.
What do I wrong?
The tagging didn't work for me. It shows created, but nothing appears on github. However, I managed to achieve tagging by creating pre-release. Which is not ideal, but still better than nothing:
curl --location --request POST
'https://<giturl>/repos/{owner}/{repo}/releases' \
--header 'Authorization: Basic xxx' \
--header 'Content-Type: application/vnd.github.v3+json' \
--data-raw '{
"tag_name": "v0.0.1",
"target_commitish": "master",
"name": "v0.0.1",
"body": "This is for Release v0.0.1 of the product",
"draft": false,
"prerelease": true}'
There are two types of tags -- annotated and lightweight, you can check the difference here.
As Github API puts, /repos/:owner/:repo/git/tags only created an annotated tag object, and then you should manually create a refrence with the sha of this tag object by calling create refrence api:
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/OWNER/REPO/git/refs \
-d '{"ref":"refs/tags/tagName","sha":"the sha of tag object"}'
In another case, if you only want to add a lightweight tag to one commit, you should directly call create refrence api without the first step:
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/OWNER/REPO/git/refs \
-d '{"ref":"refs/tags/tagName","sha":"the sha of the commit that you want to tag"}'
Please advise, how to remove files inside a container using the Docker API?
I have tried to do it this way, but it doesn't work
curl --location --request POST 'http://192.168.1.55:5555/containers/{id}/exec' \
--header 'Content-Type: application/json' \
--data-raw '{
"Cmd": [
"/bin/sh",
"-c",
"'rm -rf /files/*'"
]
}'
According to the Docker API doc "To exec a command in a container, you first need to create an exec instance, then start it. These two API endpoints are wrapped up in a single command-line command, docker exec." In this way, after getting the response you must run new POST request /exec/{id}/start
I have an upcoming tool migration where I can import assignees but not inactive ones - and there is no user group by default with only active users.
So I've exported all jira users and filtered based on active - so I have a nice list of all their usernames/emails. Now I want to use the REST API to create a usergroup from the list and add each user.
From the API documentation, it's pretty straightforward:
curl --request POST \
--url '/rest/api/3/group/user' \
--header 'Authorization: Bearer <access_token>' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"accountId": "384093:32b4d9w0-f6a5-3535-11a3-9c8c88d10192"
}'
However, I'm not about to type in one by one the accountIds. How can I specify an excel list or how else can i achieve this?
Easier than I thought - Just made a bash script where accountId's is the variable to cycle through the addresses.
I am trying to use api to add new key to a path, say secret/sub path. In that path I already have two keys values, I want to add one more, the following is my api
curl --request POST --data '{"bar": "baz"}' http://127.0.0.1:8200/v1/secret/sub/cha3
The result was it didn't append this new key under secret/sub path, instead it created another new path named 'sub' under secret/secrets!
Any idea how to do add a new key? Guess I want to append new key to existing path.
My vault version is 1.0.3
curl \
--header "X-Vault-Token: ..." \
--request POST \
--data '{"bar": "baz"}' \
https://127.0.0.1:8200/v1/secret/data/sub
If you want to add more data to the same path, you will need to specify the old params (otherwise it will override it):
curl \
--header "X-Vault-Token: ..." \
--request POST \
--data '{"bar": "baz", "foo": "fee"}' \
https://127.0.0.1:8200/v1/secret/data/sub
See the documentation for more details
Here is the command I am using to test the text-to-speech API:
/usr/bin/curl -k -u 'USERNAME':'PASSWORD' -X POST \
--header 'Content-Type: application/json' \
--header 'Accept: audio/wav' \
--data '{"text":"hellow world","voice":"en-US_AllisonVoice"}' \
'https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize' > ./public/138106.wav
The command above doesn't seem to generate the desired audio file. I have a bluemix account and the right credentials. An audio file is generated, but it's corrupt.
voice is a URL parameter. The correct curl command looks like this:
/usr/bin/curl -k -u 'USERNAME':'PASSWORD' -X POST \
--header 'Content-Type: application/json' \
--header 'Accept: audio/wav' \
--data '{"text":"hellow world"}' \
'https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?voice=en-US_AllisonVoice'
Disclosure: I am an evangelist for IBM Watson.
--data '{"text":"hellow world","voice":"en-US_AllisonVoice"}'
Try this:
--data "{\"text\":\"hello world\", \"voice\":\"en-US_AllisonVoice\"}"
I took this syntax from the API documentation found here: https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/text-to-speech/quick-curl.shtml
It seems they have built the syntax of the JSON differently than your command.
I solved it not using the cURL scripting recommendation.
But by going directly to the url: https://stream.watsonplatform.net/speech-to-text/api/v1/recognize
Then removing the following 2 lines:
"word_alternatives_threshold": null,
"keywords_threshold": null,
There are issues with these lines.