React Native
React Native
Quickbooks Delete an Invoice
See more QuickBooks Examples
Demonstrates how to delete an invoice using the Quickbooks REST API.Chilkat React Native Downloads
import { JsonObject, Rest, StringBuilder } from '@chilkat/react-native'
async function chilkatExample() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// First get our previously obtained OAuth2 access token.
const jsonToken = new JsonObject();
jsonToken.loadFile('qa_data/tokens/qb-access-token.json');
const rest = new Rest();
// Connect to the REST server.
const bTls = true;
const port = 443;
const bAutoReconnect = true;
await rest.connectAsync('sandbox-quickbooks.api.intuit.com', port, bTls, bAutoReconnect);
const sbAuth = new StringBuilder();
sbAuth.append('Bearer ');
sbAuth.append(jsonToken.stringOf('access_token'));
rest.authorization = sbAuth.getAsString();
// --------------------------------------------------------------------------
// Note: The above code to setup the initial REST connection
// can be done once. After connecting, any number of REST calls can be made.
// If the connection is lost, the next REST method call will automatically
// reconnect if needed.
// --------------------------------------------------------------------------
// Create the following JSON:
// {
// "SyncToken": "3",
// "Id": "33"
// }
//
// Use the this online tool to generate the code from sample JSON:
// Generate Code to Create JSON
const jsonReq = new JsonObject();
jsonReq.updateString('SyncToken', '3');
jsonReq.updateString('Id', '33');
const sbRequestBody = new StringBuilder();
jsonReq.emitSb(sbRequestBody);
rest.addHeader('Content-Type', 'application/json');
rest.addHeader('Accept', 'application/json');
rest.allowHeaderFolding = false;
const sbResponseBody = new StringBuilder();
try {
await rest.fullRequestSbAsync('POST', '/v3/company/<realmID>/invoice?operation=delete', sbRequestBody, sbResponseBody);
} catch {
console.log(rest.lastErrorText);
return;
}
const respStatusCode = rest.responseStatusCode;
// Success is indicated by a 200 response status code.
console.log(`response status code = ${respStatusCode}`);
const jsonResponse = new JsonObject();
jsonResponse.loadSb(sbResponseBody);
jsonResponse.emitCompact = false;
console.log(jsonResponse.emit());
if (rest.responseStatusCode !== 200) {
console.log('Failed.');
return;
}
// Sample output...
// (See the parsing code below..)
//
// Use the this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// {
// "Invoice": {
// "status": "Deleted",
// "domain": "QBO",
// "Id": "33"
// },
// "time": "2013-03-15T00:18:15.322-07:00"
// }
//
const invoiceStatus = jsonResponse.stringOf('Invoice.status');
const invoiceDomain = jsonResponse.stringOf('Invoice.domain');
const invoiceId = jsonResponse.stringOf('Invoice.Id');
const time = jsonResponse.stringOf('time');
}