Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 3

Getting Error "Problems parsing JSON" while making POST call to create tree

{
"base_tree": "2267699d5ea2a632c625693ceef5f7b77b2cda74",
"tree": [
              {
                   "path": "synthetics/MyAccount-MakeAPayment.js",
                   "mode": "100644",
                    "type": "blob",
                    "content" : "require('new-relic-synthetics-manager');

"

               }

             ]

}

I have more lines to be included in the content property(more than 100 lines of the script which contains " and ').  Even at the first line, it is failing whenever there is a newline character. Please let me know how can I provide some scripts (javascript/selenium scripts) in the content property of the api call for creating a tree as mentioned in the documentation https://developer.github.com/v3/git/trees/#create-a-tree. Please note that I am trying to modify multiple files and commit all my changes at a single shot so won't be able to use  Content APi as mentioned in the documentation https://developer.github.com/v3/repos/contents/#create-a-file.
Some help at the earliest will be greatly appreciated.

Thanks in Advance

2 Replies
Highlighted
Community Manager
Message 2 of 3

Re: Getting Error "Problems parsing JSON" while making POST call to create tree

Hi,

 

Thanks for reaching out! And apologies about the delay. Are you still experiencing this issue?


Best,
AndreaG

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!

Copilot Lvl 2
Message 3 of 3

Re: Getting Error "Problems parsing JSON" while making POST call to create tree

Hi, I'm having a similiar problem...

 

I have about 300 files to update, using content api isn't acceptable due to rate/abuse limiting (I originally tried this creating a blob for each file using base64 encoding, then adding to tree via SHA)

 

Using https://developer.github.com/v3/git/trees/#create-a-tree I'm now trying to use "content" vs "sha" and create the whole tree in one shot (which although technically works) it's posting all my files as the base64 encoded string vs decoding them.

 

For lots of reasons like above, I can't put the raw string inside the JSON.  I tried adding encoding to the json in hopes it would work but it doesn't.  Is there a reason create tree content doesn't default/use base64 encoding?

 

Sample JSON creation:

'{ "path": "' + path + macroName + ".macro" + '", "mode": "100644", "type": "blob", "content": "' + macroEncoded + '", "encoding": "base64" }'