Code snippets [Sep 17]

:raising_hand_man: emdax asked

It would be great to have JavaScript examples of using the API , all-apis.nocodb.com doesn’t really show how call the methods properly

:man_bald: dstala replied

On v0.96.2, you can find sample code snippets menu here

:man_bald: dstala replied

We are updating documents as per new UI. should be ready in few days

:man_bald: dstala replied

this menu will open-up code snippets for your project table in in different programming languages

:raising_hand_man: emdax replied

thank you

:raising_hand_man: emdax replied

Does the API snippet update to reflect Filter/Sort setting of view?

:man_bald: dstala replied

No. Snippet is static. Something like below for JS

```shell

import axios from “axios”;

const options = {

method: ‘GET’,

url: ‘http://localhost:8080/api/v1/db/data/noco/p_6bba84fwrupxcj/City/views/City’,

params: {offset: ‘0’, limit: ‘25’, where: ‘’},

headers: {

‘xc-auth’: ‘eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InVzZXJAbm9jb2RiLmNvbSIsImZpcnN0bmFtZSI6bnVsbCwibGFzdG5hbWUiOm51bGwsImlkIjoidXNfeHBrZm12dzBmM3oyZHQiLCJyb2xlcyI6InVzZXIsc3VwZXIiLCJ0b2tlbl92ZXJzaW9uIjoiZDdmNTI2YzcwM2JmNmM0N2VjZjNjYjUyZmRjMjUxYjU4NWJiYTFiMDVjMjAyY2IyNjVjYTQ5NDNhZGZlNzMyMmU1ZTlhYjA2MWM1MTk5Y2IiLCJpYXQiOjE2NjI3OTg4ODUsImV4cCI6MTY2MjgzNDg4NX0.sB3pBy7_IAu4LvcrZ-AJ29OhKd-VbFiLzvy1u-wHXcM’

}

};

axios.request(options).then(function (response) {

console.log(response.data);

}).catch(function (error) {

console.error(error);

});

```

:raising_hand_man: emdax replied

getting: Request header field xc-auth is not allowed by Access-Control-Allow-Headers in preflight response.

:man_bald: dstala replied

You can also try Swagger for experimenting with APIs

image0

:raising_hand_man: emdax replied

Error: Request header field xc-auth is not allowed by Access-Control-Allow-Headers in preflight response.

:man_bald: dstala replied

<@372124593848057866> can you provide details about the API that you are trying out? with any sensitive information redacted?

:raising_hand_man: emdax replied

I just want to load filtered sorted view

:raising_hand_man: emdax replied

in JSON

:raising_hand_man: emdax replied

with fetch

:person_tipping_hand: o1lab replied

you would have to use API token with xc-token header

:person_tipping_hand: o1lab replied

https://docs.nocodb.com/developer-resources/accessing-apis#api-token

:person_tipping_hand: o1lab replied

xc-auth has a default expiry of 1 day

:raising_hand_man: emdax replied

How do you set up NocoDB , to run on PORT 80 with SSL/HTTPS ?

:raising_hand_man: emdax replied

Use NGINX ?

:raising_hand_man: emdax replied

API is giving CORS errors when called from the browser