Save state item
POSThttps://http-prj1234.api.cloud.diagrid.io/v1.0/state/:storeName
This endpoint lets you save multiple items to the state store.
Request
Path Parameters
storeName stringrequired
Possible values: Value must match regular expression ^[a-zA-Z0-9_-]+$
The name of your state store.
- application/json
Body
array
required
Array [
]
key stringrequired
Possible values: Value must match regular expression ^[a-zA-Z0-9_-]+$
value objectrequired
etag string
metadata
object
options
object
Responses
- 204
- 400
- 500
State saved.
State store is missing or misconfigured or malformed request.
Failed to save state.
- python
- java
- csharp
- nodejs
- go
- Python
# pip3 install dapr certifi requests
# ---
from dapr.clients import DaprClient
import os
os.environ["DAPR_API_TOKEN"] = "{{ .DaprAPIToken }}"
os.environ["DAPR_HTTP_ENDPOINT"] = "{{ .DaprHTTPEndpoint }}"
os.environ["DAPR_GRPC_ENDPOINT"] = "{{ .DaprGRPCEndpoint }}"
with DaprClient() as d:
d.save_state(store_name="{{ .KVStore }}", key="mykey", value="myvalue")
- REQUESTS
- HTTP.CLIENT
import requests
import json
url = "https://http-prj1234.api.cloud.diagrid.io/v1.0/state/:storeName"
payload = json.dumps([
{
"key": "string",
"value": {
"name": "John Doe",
"age": 30
},
"etag": "",
"metadata": {
"ttlInSeconds": "string"
},
"options": {}
}
])
headers = {
'Content-Type': 'application/json',
'dapr-api-token': '<API_KEY_VALUE>'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
ResponseClear