Categories

CRUD endpoints for a user's categories

Please note that in all urls & code samples you'll need to replace:username and :corporation with appropriate values

Get All Categories

GET /v2/organization/:corporation/staff/:username/category

Headers

Url

Response

 {
  data: [
    {
      id: 1,
      category_id: 1,
      category: "category name"
    }
  ],
  success: true
}

Code

const accessToken = `<ACCESS TOKEN>`

fetch('https://public-api.expertfile.com/v2/organization/:corporation/staff/:username/category', {
    method: 'GET',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Authorization': `Bearer ${accessToken}`
    }
})
.then(response => response.json())
.then(json => {
    const { success, data } = json

    if (success) {
        const category = data
        console.log('category', category)
    }

})
.catch(error => console.error(error));

Get Individual Category

GET /v2/organization/:corporation/staff/:username/category/:id

Headers

Url

Response

{
  data: [
    {
      id: 1,
      category_id: 1,
      category: "category name"
    }
  ],
  success: true
}

Code

const accessToken = `<ACCESS CODE>`

fetch('https://public-api.expertfile.com/v2/organization/:corporation/staff/:username/category/:id', {
    method: 'GET',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Authorization': `Bearer ${accessToken}`
    }
})
.then(response => response.json())
.then(json => {
    const { success, data } = json

    if (success) {
        const category = data
        console.log('category', category[0])
    }

})
.catch(error => console.error(error));

Create Category

POST /v2/organization/:corporation/staff/:username/category

Headers

Url

Body

Response

{ 
    data: { 
        id: 1
    }, 
    success: true 
}

Code

const data = new URLSearchParams();
const accessToken = `<ACCESS TOKEN>`

data.append('name', 'Test');

fetch('https://public-api.expertfile.com/v2/organization/:corporation/staff/:username/category', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Authorization': `Bearer ${accessToken}`
    },
    body: data
})
.then(response => response.json())
.then(json => {
    const { success, data, error } = json

    if (success) {
        const { id } = data
        console.log('New category id', id)
    }

})
.catch(error => console.error(error));

Delete Category

DELETE/v2/organization/:corporation/staff/:username/category/:id

Headers

Url

Response

{ 
    data: { 
        deleted: true, 
        id: 1
    }, 
    success: true 
}

Code

const accessToken = `<ACCESS TOKEN>`

fetch('https://public-api.expertfile.com/v2/organization/:corporation/staff/:username/category/:id', {
    method: 'DELETE',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Authorization': `Bearer ${accessToken}`
    }
})
.then(response => response.json())
.then(json => {
    const { success, data, error } = json

    if (success) {
        const { id } = data
        console.log('Deleted category id', id)
    }

})
.catch(error => console.error(error));

Last updated