Array to Json Format in Deluge - zoho

How do you convert array to a JSON Format in Deluge?
The return of response is a array.
response = zoho.creator.getRecords("zoho_user12586", "pilmico-duplicate", "Add_New_Employee_Record_Report", "", 1, 1000, "creator_auth");

If you need to make a post request:
header_data = {"Content-Type":"application/json"};
response = response.toText();
req = postUrl("URL",response,header_data);

Related

OkHttp - keep getting the error: "content-type of request should be application/json"

Why do I get this error "content-type of request should be application/json", because I encoded it application/json?
How to correct it?
In Postman the request is working fine.
int id = 208;
MediaType JsonType = MediaType.parse("application/json");
OkHttpClient client = new OkHttpClient();
String jsonBody = "{\"params\":[\"wandelnet\"," + id + "]}";
RequestBody body = RequestBody.create(jsonBody, JsonType);
Request request = new Request.Builder()
.url( "https://wandelnet.api.routemaker.nl/routemaker/getPublishedRoute")
.post(body)
.addHeader("Content-Type", "application/json; charset=utf-8")
.addHeader( "Accept", "application/json")
.build();
Response response = client.newCall(request).execute();
The result is:
{"result":null,"error":{"code":"sherpaBadRequest","message":"content-type
of request should be application/json"}}
Try creating the request body from bytes, not from a string:
RequestBody body = RequestBody.create(jsonBody.getBytes(“UTF-8”), JsonType);
OkHttp automatically adds a charset when it does string encoding, and we need to prevent this here.
You’ll also want to omit the Content-Type header in your request builder.

Chilkat2-Python - HTTP Form Authentication problem

Trying to convert from python request to chilkat2.HttpRequest :
import requests
data = {"username": "user","password": "pass","remember": "on"}
sign_in_url = 'https://www.tradingview.com/accounts/signin/'
signin_headers = {'Referer': 'https://www.tradingview.com'}
response = requests.post(url=sign_in_url, data=data, headers=signin_headers)
token = response.json()['user']['auth_token']
P.S. Cause no right username and password - will return status_code:200
b'{"error":"Invalid username or password","code":"invalid_credentials"}'
I have this:
http = chilkat2.Http()
req = chilkat2.HttpRequest()
req.AddParam("username","user")
req.AddParam("password","pass")
req.AddParam("remember","on")
req.Path = '/accounts/signin/'
req.HttpVerb = "POST"
http.FollowRedirects = True
http.SendCookies = True
http.SaveCookies = True
http.CookieDir = "memory"
resp = http.SynchronousRequest('www.tradingview.com',443,True,req)
print(http.LastErrorText)
But response - statusCode: 403 Forbidden
What am I doing wrong?
See the tradingview.com API documentation: https://www.tradingview.com/rest-api-spec/#section/Authentication
You can see that an application/x-www-form-urlencoded POST is required.
It's easy to do with Chilkat. See this documentation showing how to send common HTTP request types: https://www.chilkatsoft.com/http_tutorial.asp
You'll want to send a request like this: https://www.chilkatsoft.com/http_post_url_encoded.asp

Malformed request from aiohttp.ClientSession().post() with multiple image files

I'm still relatively new to Python and my first time to use aiohttp so I'm hoping someone can help spot where my problem is.
I have a function that does the following:
retrieves from the JSON payload two base64 strings - base64Front and base64Back
decode them, save to "images" folder
send the Front.jpg and Back.jpg to an external API
this external API expects a multipart/form-data
imgDataF = base64.b64decode(base64FrontStr)
frontFilename = 'images/Front.jpg'
with open(frontFilename, 'wb') as frontImgFile:
frontImgFile.write(imgDataF)
imgDataB = base64.b64decode(base64BackStr)
backFilename = 'images/Back.jpg'
with open(backFilename, 'wb') as backImgFile:
backImgFile.write(imgDataB)
headers = {
'Content-Type': 'multipart/form-data',
'AccountAccessKey': 'some-access-key',
'SecretToken': 'some-secret-token'
}
url = 'https://external-api/2.0/AuthenticateDoc'
files = [('file', open('./images/Front.jpg', 'rb')),
('file', open('./images/Back.jpg', 'rb'))]
async with aiohttp.ClientSession() as session:
async with session.post(url, data=files, headers=headers) as resp:
print(resp.status)
print(await resp .json())
The response I'm getting is status code 400 with:
{'ErrorCode': 1040, 'ErrorMessage': 'Malformed/Invalid Request detected'}
If I call the url via Postman and send the two jpg files, I get status code 200.
Hope someone can help here.
Thanks in advance.
Try using FormData to construct your request. Remove the content type from header and use it in FormData field as below:
data = FormData()
data.add_field('file',
open('Front.jpg', 'rb'),
filename='Front.jpg',
content_type='multipart/form-data')
await session.post(url, data=data)
Reference: https://docs.aiohttp.org/en/stable/client_quickstart.html#post-a-multipart-encoded-file

Invalid Response - JSON & Laravel 5. 6

In my code below is a json response that i am trying to access its element. When i get the description from the response, i get an error. Below is the structure of the response
How do i get the description from the response ? I am only able to get success by $response->success
Response
{"description":["My Description Is Here"],"success":true}
When i validate the json, it is actually a valid json. What could i be doing wrong ?
Code
$response = {"description":["My Description Is Here"],"success":true}
if ($response->state == true) {
$message = $response->detail;
} else {
//do something here
}
You are trying to work with JSON in PHP. But at first you have to decode it into object:
$response = json_decode('{"description":["My Description Is Here"],"success":true}');

undefined byte_size for hash

Im trying to get around a get request in ruby.
uri = URI.parse(ENV["DATA_URL"])
http = Net::HTTP.new(uri.host, uri.port)
headers["Authorization"] = data["authHeader"]
request = Net::HTTP::Get.new(uri.request_uri,headers)
response = http.request( request, form_data )
JSON.parse(response.body)
Im not sure why this is happening, any help is appreciated
Your form_data is probably a Hash and it needs to be formatted into a string. Try:
formatted_data = URI.encode_www_form(form_data)
response = http.request( request, formatted_data )
http://docs.ruby-lang.org/en/trunk/URI.html#method-c-encode_www_form
Issue could be because of form_data attribute. I use URI.encode_www_form when passing the data. You can refer here for URI::encode_www_form
You could do URI.encode_www_form( form_data ) and fix the issue

Resources