Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

How to work with Directus API

I tried to create a new record for "Test_Collection" collection in directus with this function in ApiService.ts file

 public static test() {
 ApiService.vueInstance.axios
 .post("/items/Test_Collection", { name: "test", result: "123" }, {
 headers: { "Content-type": "application/json;" },
 })
 .catch((error) => {
 throw new Error(`[KT] ApiService ${error}`);
 });
 }

the API still reached my directus backend but the payload became an empty Object {}, it only happen when the API is called through ApiService.ts file. If i call the API like this from anywhere else it work normally

 handleTestInsert3() {
 ApiService.vueInstance.axios.post('/items/Test_Collection', { name: "test", result: "123" }, { headers: { 'Content-Type': 'application/json' } }
 ).catch((error) => {
 throw new Error(`[KT] ApiService ${error}`);
 });
 }

i wonder if there anyway to make it work as intended

Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (1)


Hi,

Sorry for the late reply.

Currently, we haven't tried integrating Metronic with the Directus API, but we will explore this possibility if there is sufficient demand.

Please ensure that your backend correctly retrieves the request data. To verify that your API is functioning properly, you can test the request using Postman.

Additionally, let us know if you encounter any client errors when making this request.

Regards,
Lauris Stepanovs,
Keenthemes Support Team


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(