Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type definition for organizations updateMany appears to be incorrect #437

Open
tonyherr opened this issue Jan 5, 2025 · 0 comments
Open
Labels

Comments

@tonyherr
Copy link

tonyherr commented Jan 5, 2025

Describe the Bug
updateMany for organizations appears to have an incorrect type definition and example in:
/node-zendesk/dist/types/clients/core/organizations.d.ts

The current type definition for client.organizations.updateMany

(method) Organizations.updateMany(organizations: object[]): Promise<{
    response: object;
    result: object[];
}>

With the example
const updatedOrganizations = await client.organizations.updateMany([{ id: 1, name: 'Updated Org1' }, { id: 2, name: 'Updated Org2' }]);

Things work if I change the type definition param to object instead of object[] and use a parameter such as:
const updatedOrganizations = await client.organizations.updateMany({organizations: [{ id: 1, name: 'Updated Org1' }, { id: 2, name: 'Updated Org2' }]});

Example Code
Doesn't work
const updatedOrganizations = await client.organizations.updateMany([{ id: 1, name: 'Updated Org1' }, { id: 2, name: 'Updated Org2' }]);

Works:
const updatedOrganizations = await client.organizations.updateMany({organizations: [{ id: 1, name: 'Updated Org1' }, { id: 2, name: 'Updated Org2' }]});

Expected Behavior
Multiple organizations to be updated

Actual Behavior
with debug turned on:

{
  type: 'debug::request',
  detail: {
    username: 'redacted,
    token: 'redacted',
    subdomain: 'redacted',
    throwOriginalException: true,
    debug: true,
    endpointUri: 'redacted,
    get: [Function: get],
    headers: {
      Authorization: 'Basic redacted=',
      'Content-Type': 'application/json',
      Accept: 'application/json',
      'User-Agent': 'node-zendesk/6.0.1 (node/20.11.0)'
    },
    uri: 'https://redacted/api/v2/organizations/update_many.json',
    method: 'PUT',
    body: undefined
  },
  result: 'undefined'
}
{
  type: 'debug::response',
  detail: {
    json: [Function: json],
    status: 400,
    headers: { get: [Function: get] },
    statusText: 'Bad Request'
  },
  result: 'undefined'
}
{
  type: 'debug::result',
  detail: {
    error: 'ParameterMissing',
    description: 'Parameter organizations or (organization and ids/external_ids) is required'
  },
  result: 'undefined'
}
Error updating orgs: Zendesk Error (400): Bad Request [
  {
    id: 1,
    organization_fields: {
      redacted: 10,
    }
  },
  {
    id: 2,
    organization_fields: {
      redacted: 12,
    }
  }
]

"Fixed" type definition:

(method) Organizations.updateMany(organizations: object): Promise<{
    response: object;
    result: object[];
}>

Debug info after editing the type definition:

{
  type: 'debug::request',
  detail: {
    username: 'redacted',
    token: 'redacted,
    subdomain: 'redacted',
    throwOriginalException: true,
    debug: true,
    endpointUri: 'https://redacted.zendesk.com/api/v2',
    get: [Function: get],
    headers: {
      Authorization: 'Basic redacted=',
      'Content-Type': 'application/json',
      Accept: 'application/json',
      'User-Agent': 'node-zendesk/6.0.1 (node/20.11.0)'
    },
    uri: 'https://redacted.zendesk.com/api/v2/organizations/update_many.json',
    method: 'PUT',
    body: '{"organizations":[{"id":1,"organization_fields":{"redacted":10}},{"id":2,"organization_fields":{"redacted":12,}}]}'
  },
  result: 'undefined'
}
{
  type: 'debug::response',
  detail: {
    json: [Function: json],
    status: 200,
    headers: { get: [Function: get] },
    statusText: 'OK'
  },
  result: 'undefined'
}
{
  type: 'debug::result',
  detail: {
    job_status: {
      id: 'V3-redacted',
      job_type: 'Batch Update Organization',
      url: 'https://redacted.zendesk.com/api/v2/job_statuses/V3-redacted.json',
      total: 2,
      progress: null,
      status: 'queued',
      message: null,
      results: null
    }
  },
  result: 'undefined'
}

And the organizations are updated in Zendesk.

Environment Information

  • node-zendesk 6.0.1:
  • Node.js version: 20.11
  • Operating System: mac os
  • Any other relevant software versions?

Additional Context
Add any other context about the problem here.

@tonyherr tonyherr added the bug label Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant