Sendgrid-php: headers() no longer returned as an associative array

Created on 15 Nov 2018  路  5Comments  路  Source: sendgrid/sendgrid-php

Issue Summary

It seems that $response->headers() does not return an associative array, although https://github.com/sendgrid/sendgrid-php/issues/361 and https://github.com/sendgrid/php-http-client/pull/19 say it should

How can we reliably get that value?

(The docs say "When using the Event Webhook, it's a best practice to store your X-Message-ID." so we'll do that, just need to know how to get it. Thanks!)

Steps to Reproduce

  1. $response = $sendgrid->send($email);
  2. var_dump($response->headers());

Technical details:

  • sendgrid-php Version: 7.2
  • PHP Version: 5.6
unknown or a question

Most helpful comment

Ah I missed that, thanks yes that works

All 5 comments

Hi @KayakinKoder, thank you for your report.
Can you provide the response headers output that you get?

Thanks.

@peter279k yes, thanks

array (
  0 => 'HTTP/1.1 202 Accepted',
  1 => 'Server: nginx',
  2 => 'Date: Thu, 15 Nov 2018 17:28:20 GMT',
  3 => 'Content-Type: text/plain; charset=utf-8',
  4 => 'Content-Length: 0',
  5 => 'Connection: keep-alive',
  6 => 'X-Message-Id: v8TRYFfWRu2BOIOCqlvX_w',
  7 => 'Access-Control-Allow-Origin: https://sendgrid.api-docs.io',
  8 => 'Access-Control-Allow-Methods: POST',
  9 => 'Access-Control-Allow-Headers: Authorization, Content-Type, On-behalf-of, x-sg-elas-acl',
  10 => 'Access-Control-Max-Age: 600',
  11 => 'X-No-CORS-Reason: https://sendgrid.com/docs/Classroom/Basics/API/cors.html',
  12 => '',
  13 => '',
)

@KayakinKoder, thank you for your reply.

According to this PR, it seems that the headers method has the optional argument and determine the response headers array is associative or normal.

Can you use var_dump($response->headers(true)); then try again? Thanks.

Ah I missed that, thanks yes that works

Thanks for helping out @peter279k!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

izhukovich picture izhukovich  路  4Comments

micahwalter picture micahwalter  路  3Comments

morazain picture morazain  路  3Comments

iamanupammaity picture iamanupammaity  路  4Comments

Aubynj picture Aubynj  路  3Comments