Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API] Document public API #809

Open
AlexeySachkov opened this issue Nov 23, 2018 · 6 comments
Open

[API] Document public API #809

AlexeySachkov opened this issue Nov 23, 2018 · 6 comments

Comments

@AlexeySachkov
Copy link
Member

I found a few issues where people asking some questions about an existing API trying to setup some integration of their tools with the Homebrewery.

I think we could document API to simplify integration of external tools with the Hombrewery.

See #194, #162

@calculuschild calculuschild added this to Backlog in Issues Organizer Oct 26, 2020
@G-Ambatte
Copy link
Collaborator

The API doesn't appear to be restricted at the moment; I was able to create a new brew as an anonymous user by using the following chunk of JS:

test.js

const request = require('superagent');

const res = request.post('https://homebrewery.naturalcrit.com/api')
				.send({ title: "Test Title", text: "# Test Text" })
				.catch((err)=>{
					console.log('Error creating Local Copy');
					this.setState({ errors: err });
					return;
				})
				.then(function(result) {
					console.log(result.body);
					return result;
				});

Running node test.js resulted in the following:

{
  title: 'Test Title',
  description: '',
  tags: '',
  systems: [],
  renderer: '',
  authors: [],
  published: false,
  views: 0,
  version: 1,
  _id: '6104b739fbfbf400179b0915',
  shareId: 'Hdpt5VKlbI1n',
  editId: 'DomQTQp4BtO7',
  createdAt: '2021-07-31T02:36:41.144Z',
  updatedAt: '2021-07-31T02:36:41.144Z',
  lastViewed: '2021-07-31T02:36:41.144Z',
  textBin: 'U1YISS0uARIVJQA=',
  gDrive: false
}

I was then able to access the resultant brew via https://homebrewery.naturalcrit.com/edit/DomQTQp4BtO7 and https://homebrewery.naturalcrit.com/share/Hdpt5VKlbI1n.

@G-Ambatte
Copy link
Collaborator

Unless I've missed something, it doesn't currently seem possible to set authors: [] from the new Brew API; the current code checks for the existence of req.account and if found, sets authors: [req.account.username]. Attempting the following still results in a brew with authors: []:

const request = require('superagent');

const res = request.post('https://homebrewery.naturalcrit.com/api')
				.send({ title: "Test Title", text: "# Test Text", account: { username: "my_account_name" } })
				.catch((err)=>{
					console.log('Error creating Local Copy');
					this.setState({ errors: err });
					return;
				})
				.then(function(result) {
					console.log(result.body);
					return result;
				});

Following the /edit link and then saving the Brew updates the authors array to include the username.

@calculuschild
Copy link
Member

calculuschild commented Jul 31, 2021

That looks right. We probably don't want anyone to be able to create files on another person's account.

I'm not even sure what use case somebody would have to directly create documents in the database. Generating a brew to New? That makes more sense to me.

@G-Ambatte
Copy link
Collaborator

It should be possible to add parameters like title, text, style, etc. to /new (or a similar Route), allowing users to programmatically generate a New brew that can then be printed directly or saved to a HB user account.

@5e-Cleric
Copy link
Member

5e-Cleric commented May 18, 2024

I don't see why anyone would want that other than to use another UI to make documents. Considering closing this.

@dbolack-ab
Copy link
Collaborator

I don't see why anyone would want that other than to use another UI to make documents. Considering closing this.

Seconded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants