slate/components/api-docs/v2/update-slate.js

80 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-04-21 03:14:43 +03:00
import * as React from "react";
import * as System from "~/components/system";
import CodeBlock from "~/components/system/CodeBlock";
const EXAMPLE_CODE_JS = (key, slateId) => {
return `const COLLECTION_ID = "${slateId}"
2021-04-21 03:14:43 +03:00
const collectionResponseData = getCollectionById(COLLECTION_ID);
2021-04-21 03:14:43 +03:00
const collection = collectionResponseData.collection;
collection.data.name = "New title"
2021-04-21 03:14:43 +03:00
const response = await fetch('https://slate.host/api/v2/update-collection', {
2021-04-21 03:14:43 +03:00
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: '${key}', // API key
2021-04-21 03:14:43 +03:00
},
body: JSON.stringify({ data: collection })
});
const json = await response.json();`;
2021-04-21 03:14:43 +03:00
};
const EXAMPLE_CODE_PY = (key, slateId) =>
`import requests
headers = {
"content-type": "application/json",
"Authorization": "${key}", # API key
2021-04-21 03:14:43 +03:00
}
json = { "id": "${slateId}" } # collection ID
2021-04-21 03:14:43 +03:00
get_collection = requests.post(
"https://slate.host/api/v2/get-collection", headers=headers, json=json
2021-04-21 03:14:43 +03:00
)
get_collection_response = get_collection.json()
2021-04-21 03:14:43 +03:00
collection = get_collection_response["collection"]
collection["data"]["name"] = "New title"
2021-04-21 03:14:43 +03:00
postJson = { "data": collection }
2021-04-21 03:14:43 +03:00
url = "https://slate.host/api/v2/update-collection"
2021-04-21 03:14:43 +03:00
r = requests.post(url, headers=headers, json=postJson)`;
export default class APIDocsUpdateCollection extends React.Component {
2021-04-21 03:14:43 +03:00
render() {
let language = this.props.language;
let key = this.props.APIKey;
let slateId = this.props.slateId;
let code = {
javascript: EXAMPLE_CODE_JS(key, slateId),
python: EXAMPLE_CODE_PY(key, slateId),
};
return (
2021-08-02 05:56:55 +03:00
<div css={this.props.cssValue} style={this.props.style}>
2021-04-21 03:14:43 +03:00
<System.DescriptionGroup
2021-08-02 05:56:55 +03:00
style={{ maxWidth: 640 }}
label="Update collection"
description="This API endpoint allows you to modify a collection by saving the response from get-collection, modifying it, and sending it back"
2021-04-21 03:14:43 +03:00
/>
<CodeBlock
children={code}
style={{ maxWidth: "820px" }}
language={language}
title="Update collection"
2021-04-21 03:14:43 +03:00
multiLang="true"
onLanguageChange={this.props.onLanguageChange}
/>
2021-08-02 05:56:55 +03:00
</div>
2021-04-21 03:14:43 +03:00
);
}
}