So I am getting the infamous 'Problems parsing JSON' error whenever I try to perform an API call that takes a body. I have tried both the stringified and non-stringified versions of the json:
{"path":"bin/foo","message":"[SPS-CodeDeploy] Added routing file \u0027bin/foo\u0027","content":"","branch":"foobar"}
And:
"{\"path\":\"bin/foo\",\"message\":\"[Blah] Added file \\u0027bin/foo\\u0027\",\"content\":\"\",\"branch\":\"foobar\"}"
I execute this against THIS api and I was able to run this exact call via curl without a problem.... I tried setting the content type and I tried to specify 'json' in the body, but to no avail.
PS, im doing this in Java with the apache OLTU OAuth libraries.
Here is my code:
public String writeFile(String repoPath, String contents, String branchName) throws OAuthSystemException, OAuthProblemException {
String urlPath = String.format("/repos/%s/%s/contents/%s", repoOwner, repoName, repoPath);
String message = String.format("[Blah] Added file '%s'", repoPath);
GitHubCreateFileRequest gitHubCreateFileRequest = new GitHubCreateFileRequest(repoPath, message, contents, branchName);
OAuthClientRequest bearerClientRequest = buildRequest(urlPath);
OAuthResourceResponse resp = performRequest(bearerClientRequest, "PUT", new Gson().toJson(gitHubCreateFileRequest));
if (resp.getResponseCode() >= 200 && resp.getResponseCode() < 299) {
return branchName;
}
return null;
}
private OAuthClientRequest buildRequest(String urlPath) throws OAuthSystemException {
return new OAuthBearerClientRequest(String.format("%s%s", githubUrlPrefix, urlPath))
.setAccessToken(GITHUB_OAUTH_TOKEN).buildHeaderMessage();
}
private OAuthResourceResponse performRequest(OAuthClientRequest bearerClientRequest, String verb, String body) throws OAuthProblemException, OAuthSystemException {
if (body != null) {
bearerClientRequest.setBody(body);
}
bearerClientRequest.addHeader("Content-Type", "application/json");
return oAuthClient.resource(bearerClientRequest, verb, OAuthResourceResponse.class);
}
Any ideas?
PPS
Im setting the Authorization header to bearer abcd1234.... rather than a queryparam or body