I'm making a JSON migration and it requires the header: Accept: 'application/json; charset=utf-8'

Here's my source configuration:
source:
plugin: url
data_fetcher_plugin: http
data_parser_plugin: json
authentication:
plugin: basic
username: ''
password: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
headers:
Accept: 'application/json; charset=utf-8'
Content-Type: 'application/json'
urls: https://www.example.com/jsonfeed

The authentication works, but the headers aren't passed though to getRequestHeaders()

The following patch fixes it for me, but I'm not sure whether this is a bug or not.

Here's what I've done:

Index: httpdocs/modules/contrib/migrate_plus/src/Plugin/migrate_plus/data_fetcher/Http.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- httpdocs/modules/contrib/migrate_plus/src/Plugin/migrate_plus/data_fetcher/Http.php (date 1485957865000)
+++ httpdocs/modules/contrib/migrate_plus/src/Plugin/migrate_plus/data_fetcher/Http.php (revision )
@@ -70,7 +70,7 @@
* {@inheritdoc}
*/
public function getRequestHeaders() {
- return !empty($this->headers) ? $this->headers : [];
+ return !empty($this->configuration['headers']) ? $this->configuration['headers'] : [];
}

/**

CommentFileSizeAuthor
#3 fix_headers-2849153-3.patch751 bytesmErilainen
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

spencer95 created an issue. See original summary.

joshi.rohit100’s picture

@spencer95 - that looks like a bug that headers are not available but that should not affect migration. Here is sample json migration which worked for me without header info https://github.com/joshirohit100/migrate_training_json/blob/master/migra...

mErilainen’s picture

Assigned: Unassigned » mErilainen
Priority: Normal » Major
Status: Active » Needs review
FileSize
751 bytes

I came to same conclusion, with this patch I managed to read tweets from Twitter API, which requires a Bearer token to be passed and also requires the "Accept: application/json" header to be set.

jcnventura’s picture

mikeryan’s picture

Assigned: mErilainen » Unassigned
Status: Needs review » Closed (duplicate)

Yes, #2640512: Make custom headers an HTTP-specific feature should address this by referencing the configuration directly, thanks.