We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all, hoping somebody might be able to point me in the direction as im struggling to find a way to upload a json file to a WordPress site. Im currently trying to post the file to the "/wp-json/wp/v2/media/" location using the HTTP-Requests-for-Processing library but im getting back some errors and to be honest im not really sure what im doing any more lol!
Was hoping someone might have some ideas as to the best method of uploading a json file to the wordpress uploads location so i can hopefully use the json with a sketch that will run on the site.
I will post an example of the code i have been trying :)
Answers
While the code doesnt raise any errors in processing i get the following response:
Reponse Content: {"code":"rest_invalid_json","message":"Invalid JSON body passed.","data":{"status":400,"json_error_code":4,"json_error_message":"Syntax error"}}
Any help with best options to upload files to wordpress using processing would be greatly appreciated.
Little experience but you could serialized ypur data and add it to a get request and the process it in WP side. This relies in two assumptions:
This is an idea. There could be better ways to do this and hopefully you get some other suggestions here.
Kf
Thanks Kf.
Ideas are what im looking for at the moment as im worried i might be barking up the wrong tree by heading in the route i am.
The JSON files i will be uploading are not massive but i believe some will be bigger than 2/3k. I will have a look into the idea though. It's been a while since ive done PHP but it shouldn't be an issue if i need to have some on the WP side.
Thanks,
Tom
Got it working in the end:
Can maybe be refined but does the job. It uses basic auth for now but the next step is to secure it further using OAuth, something that doesnt seem to have been done from in Processing before.
Great, thxs for sharing.
Kf
No problem. Am now trying to complete the same process with Oauth Authentication rather than Basic Authentication, it's like trying to turn a glider into the USS Enterprise lol!