Perform an API request and list the results
Accessing Deskpro data
import React from 'react';
import PropTypes from 'prop-types';
import { Phrase } from '@deskpro/apps-components';
import './styles.css';
class App extends React.Component {
static propTypes = {
dpapp: PropTypes.object.isRequired,
uiProps: PropTypes.shape({
state: PropTypes.oneOf(['ready', 'loading', 'error', 'inactive']),
display: PropTypes.oneOf(['collapsed', 'expanded', 'fullscreen']),
badgeCount: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
badgeVisibility: PropTypes.oneOf(['hidden', 'visible']),
}).isRequired,
};
state = {
attachments: [],
};
componentDidMount() {
const { dpapp } = this.props;
const ticketId = dpapp.context.props.object.props.entityId;
dpapp.restApi.get(`tickets/${ticketId}/attachments`).then(resp => {
this.setState({
attachments: resp.body.data
})
});
}
render() {
const { attachments } = this.state;
return (
<div>
<h4>Ticket attachments</h4>
{ attachments.map(attachment =>
<div key={attachment.blob.blob_id}>
<a href={attachment.blob.download_url}>{attachment.blob.filename}</a>
</div>
)}
</div>
);
}
}
export default App;Accessing another API
Last updated