Skip to content

post() method: missing minorversion, wrong Content-Type for send endpoints #2

Description

@howudodat

Summary

The post() method has three issues that cause problems with certain QuickBooks API endpoints:

1. post() hardcodes Content-Type: application/json

The QuickBooks /invoice/{id}/send endpoint requires Content-Type: application/octet-stream. Since post() hardcodes application/json, send requests fail with:

ValidationFault: Required parameter DeliveryAddress.Address is missing in the request (code 2020)

Confirmed by the Intuit developer community and verified in production.

2. post() doesn't include minorversion

The minorversion property is set to '75' in the constructor and correctly used in getCompanyInfo(), but post() never appends it:

// getCompanyInfo - correct
const url = `...?minorversion=${this.minorversion}`;

// post - missing
const url = `${this.apiBaseUrl}/v3/company/${token.realm_id}${endpoint}`;

3. query() has a typo: minorverion

const url = `...&minorverion=${this.minorversion}`;
//                 ^^^^^^^^^^^ missing 's'

Minor version is silently ignored on all queries.

Suggested Fix

Allow post() to accept an optional contentType parameter and consistently append minorversion:

async post({ token, endpoint, body, contentType = 'application/json' }) {
    token = await this.getValidToken(token);
    const separator = endpoint.includes('?') ? '&' : '?';
    const url = `${this.apiBaseUrl}/v3/company/${token.realm_id}${endpoint}${separator}minorversion=${this.minorversion}`;
    const res = await fetch(url, {
        method: 'POST',
        headers: {
            Authorization: `Bearer ${token.access_token}`,
            Accept: 'application/json',
            'Content-Type': contentType,
        },
        body: JSON.stringify(body),
    });
    return await res.json();
}

Happy to submit a PR. Environment: @balancer-team/quickbooks v0.0.18, QBO Production API, Node.js.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions