Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

113
Vistas
Multiple categories at once from Sendgrid API request returns status 400 error

I'm trying to receive the email statistics for multiple categories at once from Sendgrid API. I have @sendgrid/client installed and I'm using this peace of code:

const client = require('@sendgrid/client')
 client.setDefaultRequest('qsStringifyOptions', {arrayFormat: 'repeat'});
 client.setApiKey(process.env.SENDGRID_API_KEY)

 const request = {}
 const queryParams = {
  'aggregated_by': 'day',
  'categories': ['cat1', 'cat2'],
  'start_date': '2021-08-01',
  'end_date': '2021-09-01',
  'limit': 5,
  'offset': 1
 };
 request.qs = queryParams;
 request.method = 'GET';
 request.url = '/v3/categories/stats';
 client
  .request(request)
  .then(([response, body]) => {
    console.log(response.statusCode);
    console.log(response.body);
}).catch(function (error) {
    console.log(error)
  })

taken from https://github.com/sendgrid/sendgrid-nodejs/blob/main/packages/client/USAGE.md#get-categoriesstats. When I execute it I receive Error Code 400 and "body: { errors: [Array] }". When I replace 'categories': ['cat1', 'cat2'], with 'categories': cat1', it works. It returns Code 200 and valid Object with stats in it. What am I missing? Is this some kind of syntax error. I don't have much experience with API's.

Appreciate all your help.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

After couple chat sessions with Sendgrid support here what is end situation. By using following code

   const client = require('@sendgrid/client')
client.setApiKey(process.env.SENDGRID_API_KEY)
client.setDefaultRequest('qsStringifyOptions', {arrayFormat: 'repeat'});

const request = {}
const queryParams = {
  'aggregated_by': 'day',
  'categories': 'dallas',
  'start_date': '2021-08-31',
  'end_date': '2021-09-01',
  'limit': 1,
  'offset': 1
};
request.method = 'GET';
request.url = '/v3/categories/stats?start_date=2021-09-01&categories=cat1&categories=cat2&limit=99&aggregated_by=week';
client
  .request(request)
  .then(([response]) => {
    console.log(response.statusCode);
    console.log(response.body);
    
    }).catch(function (error) {
    console.error(error)
  })

I can retrieve stats for cat1 and cat2, but if you looking for campaigns containing both categories cat1 AND cat2, you can't do that with API. Let say you have a multiple people working on multiple markets and you are looking for stats for specific person on specific market, best solution is when creating email blast to add multiple categories: 1) salesperson_name 2) market 3) market&salesperson_name and then pull stats for market&salesperson_name category.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda