Get pull request diff from API


I can’t find how to programmatically retrieve an entire PR diff from the API.

I’m aware of{diff,patch}

but I’m specifcally interested in private repositories, and this url doesn’t seem to accept tokens in the “Authorization” header. Using cookies is not an option in this case unfortunately.

As far as I can tell there is no way to get that from either the v3 or the v4. Am I missing something?



I’m just going to bump this topic - I’ve been trying to figure out how to pull a PR diff from a github app, and it doesn’t seem to be possible? I would have thought looking at the contents of a PR would have been a super common use case, so I’m pretty baffled here.

1 Like

You have to pass a custom Accept header to request a different media format. 


$ curl -i --header "Accept: application/vnd.github.v3.diff"
HTTP/1.1 200 OK
Date: Sat, 02 Mar 2019 22:28:15 GMT
Content-Type: application/vnd.github.v3.diff; charset=utf-8
Content-Length: 172
Status: 200 OK
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 58
X-RateLimit-Reset: 1551569262
Cache-Control: public, max-age=60, s-maxage=60
Vary: Accept
ETag: "89a4add058d68717026fe382008df964"
Last-Modified: Wed, 13 Feb 2019 17:03:03 GMT
X-GitHub-Media-Type: github.v3; param=diff
Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type
Access-Control-Allow-Origin: *
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
X-Frame-Options: deny
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
Content-Security-Policy: default-src 'none'
Vary: Accept-Encoding
X-GitHub-Request-Id: D83C:7D6D:692F58:8052B4:5C7B037F

diff --git a/ b/
index 50561f3..fcc4164 100644
--- a/
+++ b/
@@ -1,3 +1,5 @@
# sandbox

just playing around don’t mind me.

You can request Accept: application/vnd.github.v3.patch, too.

It’s mentioned in the docs:

> Accept: application/vnd.github.v3.patch


Yep, this is what I was told to do by GitHub support and that’s exactly what I needed. :+1: