Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/revolunet/sellsy-proxy
Basic Sellsy API proxy for full client side apps.
https://github.com/revolunet/sellsy-proxy
api cors nodejs sellsy zeit
Last synced: about 1 month ago
JSON representation
Basic Sellsy API proxy for full client side apps.
- Host: GitHub
- URL: https://github.com/revolunet/sellsy-proxy
- Owner: revolunet
- Created: 2017-06-30T15:28:24.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-10-12T21:55:14.000Z (about 7 years ago)
- Last Synced: 2024-12-01T03:49:18.498Z (about 1 month ago)
- Topics: api, cors, nodejs, sellsy, zeit
- Language: JavaScript
- Homepage: https://github.com/revolunet/sellsy-proxy
- Size: 12.7 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sellsy proxy
Basic Sellsy API proxy; add CORS for full client side apps.
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/revolunet/sellsy-proxy&env=CONSUMER_KEY&env=CONSUMER_SECRET)
Server is deployed with `consumer` oauth keys and client must give its sellsy oauth token in each request.
## Usage
Start the server with all the consumer API keys as environment variables
```sh
set CONSUMER_KEY="xxx";
set CONSUMER_SECRET="xxx";
npm start
```## Call Sellsy API from your browser
There are two ways to query the sellsy API :
### Default : "transparent" proxy
Replace the default sellsy API endpoint with your proxy URL and it will relay all calls.
Also works with [node-sellsy](https://github.com/revolunet/node-sellsy) `endPoint` parameter.
### via /GET
Using `GET` method, pass `method` and `params` url query parameters, following Sellsy API docs.
`params` must be URL encoded.
Also add oauth headers for the proxy :
```js
// call to the API
const makeProxyRequest = ({ endPoint, method, params }) => {
// create the proxy URL
var urlParams = encodeURIComponent(params);
// build url for the proxy
var url = `${endPoint}?method=${method}¶ms=${urlParams}`;
// use native fetch API and convert to JSON
var request = new Request(url, {
headers: new Headers({
'X-USER-TOKEN': 'aaa',
'X-USER-SECRET': 'bbb',
}),
mode: 'cors'
});
return fetch(request).then(r => r.json()).catch(e => {
console.log('e', e);
throw e;
});
};makeProxyRequest({
endPoint: 'http://127.0.0.1:8282',
method: 'Document.getList',
params: JSON.stringify({
doctype: 'invoice',
search: {
contains: 'test',
},
}),
}).then(data => {
console.log(data);
});
```You'll get the raw result from the Sellsy API.
Demo : https://codesandbox.io/s/wy45kppq0k
## See also
- [node-sellsy](http://github.com/revolunet/node-sellsy)