I am sending below json request but getting error while hitting in application. below is the request format. I want to send json request which will return a xml response.
{
"Request": {
"Header": {
"Version": "1.0",
"Command": "ActiveTest",
"cc": {
"cctype": "1",
"id": "Test_id",
"Password": "********"
},
"KeyOwner": "1",
"Timestamp": "20151211121212"
},
"Body": {
"user": {
"Init": {
"idtype":"1",
"id": "88384648929",
"pass":"1234244"
},
"ActiveTest": {
}
}
}
}
}
Error:
Unexpected character '"' (code 34) in prolog; expected '<'
at [row,col {unknown-source}]: [1,1]|Param={void}
Where do you send your request to?
For me the response looks like the server expects xml and the xml-parser is complaining, that the opening < character is missing.
Related
I took this syntax for the payload from the formal docs of jira, yet i am still getting an error. I am using either python or curl both give the same error. I supppose this is a Json related issue , could you find what is wrong with the jason/payload and how do i go about fixing it?
import requests
import json
url = "https://jira.company.io/rest/api/latest/issue/ISS-37424/transitions"
payload = json.dumps({
"update": {
"comment": [
{
"add": {
"body": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "Bug has been fixed",
"type": "text"
}
]
}
]
}
}
}
]
},
"transition": {
"id": "2"
}
})
headers = {
'Authorization': 'Basic YmVzQ=LKKJYTFTgfg','
Accept': 'application/json',
'Content-Type': 'application/json',
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
I am trying to run a test suit in post man by json file upload, and executing test cases by .xl file upload.
my test.json file look like below,
{
"info": {
"_postman_id": "af0ea50c-4264-41a6-ac2c-bcacbf966394",
"name": "CCAPI TEST",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "API TEST",
"event": [
{
"listen": "test",
"script": {
"id": "c195d434-6bb6-4c00-ae21-3d71552b86f0",
"exec": [
"let expected_response = pm.variables.get(\"expected_response\");\r",
"\r",
"console.log(\"expected_response:\"+expected_response + \" ->responseBody:\"+responseBody);\r",
"pm.test(\"Body matches string\", function () {\r",
" pm.expect(responseBody).to.include(expected_response);\r",
"}); "
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
"Accept":"application/json",
"Content-Type":"application/json"
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{ip_port}}/CCAPI/subscription",
"host": [
"{{ip_port}}"
],
"path": [
"CCAPI",
"subscription"
],
}
},
"response": []
}
]
}
In postman I am passing below data in body,
{
"name":"abc",
"number":"919876567876",
"value":"ENABLE"
}
POSTMAN RESPONSE:
{
"description":"successfully added",
"status":"success"
}
I want to pass the same to the json file, I am not getting where should I add this,
for result once the test is created after uploading the file, I click on run , there I will upload the .xl file, from there It has to check for the output of the api is matching or not
.xl file contents :
name number value expected_response
abc 988988999 ENABLE {"description":"successfully
added","status":"success"}
I am not getting where to add the body of the json REQ in the .json file
If anyone tried running test suite in postman tool who knows this reply
We have a requirement where we want to hit the apis for a list of ids as async requests.
If the id is not found we receive a 404 for the specific request.
I want to know out of the two options which is a better way to handle with situation where partial content returns 200 and 404 for some of the ids.
I have evaluated two approaches.
a.
HTML Response code: 200
{
"12": {
"Response": "Success",
"StatusCode": 200,
"content": {
"title": "Shipping",
"body": ""
}
},
"13": {
"Response": "Success",
"StatusCode": 200,
"content": {
"title": "Shippin11",
"body": " "
}
},
"14": {
"Response": "Error",
"StatusCode": 404,
"ErrorMessage": "Content Not Found"
}
}
b.HTML Response code: 206
{
"data": {
"12": {
"Response": "Success",
"StatusCode": 200,
"content": {
"title": "Shipping",
"body": ""
}
}
},
"error": {
"Response": "Error",
"StatusCode": 404,
"ids": [12, 13]
}
}
Please share your thoughts.
thanks, aakash
I think it's better to use HTTP 207 Multi-Status respoince (see https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#2xx_Success). It's better sute for you task. More details in rfc: https://www.rfc-editor.org/rfc/rfc4918#page-78 (and chapter "13. Multi-Status Response").
Main idea is wrapp all requests in single "main". Main responce return HTTP 200 Ok status. Response body contain list of request's responses and some meta information about whole request: count of successed/error requests. Every single response (inside main) contein their response HTTP code (200/204/404/...) and data.
For you case it may look like:
{
"data": [
{
"content": {
"id": 12,
"title": "Shipping",
"body": ""
},
"status": 200
},
{
"resource": null,
"status": 404
},
{
"content": {
"id": 13,
"title": "Shippin11",
"body": ""
},
"status": 200
}
],
"metadata": {
"failure": 1,
"success": 2,
"total": 3
}
}
You can watch to drupal developer's inplementation:
https://gist.github.com/e0ipso/732712c3e573a6af1d83b25b9f0269c8
Another example for json-api: https://developers.getbase.com/docs/rest/articles/search/samples/batch
There is no single common perfect format, but all implementations are similar in general, but differ in detail.
I want to experiment with Google Datastore via Apps Script because I have a current solution based on Google sheets that runs into timeout issues inherent in constantly transacting with Drive files. I've created a test project in Google cloud with a service account and enabled library MZx5DzNPsYjVyZaR67xXJQai_d-phDA33
(cGoa) to handle the Oauth2 work. I followed the guide to start it up here and got all the pertinent confirmation that it works with my token (and that removing the token throws an 'authentication failed prompt').
Now I want to start with a basic query to display the one entity I already put in. I can use the API Explorer here and run this query body:
{
"query": {}
}
and get this result:
{
"batch": {
"entityResultType": "FULL",
"entityResults": [
{
"entity": {
"key": {
"partitionId": {
"projectId": "project-id-5200707333336492774"
},
"path": [
{
"kind": "Transaction",
"id": "5629499534213120"
}
]
},
"properties": {
"CommentIn": {
"stringValue": "My First Test Transaction"
},
"Status": {
"stringValue": "Closed"
},
"auditStatus": {
"stringValue": "Logged"
},
"User": {
"stringValue": "John Doe"
},
"Start": {
"timestampValue": "2017-08-17T18:07:04.681Z"
},
"CommentOut": {
"stringValue": "Done for today!"
},
"End": {
"timestampValue": "2017-08-17T20:07:38.058Z"
},
"Period": {
"stringValue": "08/16/2017-08/31/2017"
}
}
},
"cursor": "CkISPGogc35whh9qZWN0LWlkLTUyMDA3MDcwODA1MDY0OTI3NzRyGAsSC1RyYW5zYWN0aW9uGICAgICAgIAKDBgAIAA=",
"version": "1503004124243000"
}
],
"endCursor": "CkISPGogc35wcm9qZWN0LWlkLTUyMDAxxDcwODA1MDY0OTI3NzRyGAsSC1RyYW5zYWN0aW9uGICAgICAgIAKDBgAIAA=",
"moreResults": "NO_MORE_RESULTS"
}
}
I try to do the same thing with this code:
function doGet(e)
{
var goa = cGoa.GoaApp.createGoa('Oauth2-Service-Account',
PropertiesService.getScriptProperties()).execute(e);
if(goa.hasToken()) {var token = goa.getToken();}
var payload = {"query":{}}
;
var result = UrlFetchApp.fetch('https://datastore.googleapis.com/v1/projects/project-id-5200707333336492774:runQuery',
{
method: "POST",
headers: {authorization: "Bearer " + goa.getToken()},
muteHttpExceptions : true,
payload: payload
});
Logger.log(result.getBlob().getDataAsString());
}
and get this error in the logger:
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"query\": Cannot bind query parameter. 'query' is a message type. Parameters can only be bound to primitive types.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"query\": Cannot bind query parameter. 'query' is a message type. Parameters can only be bound to primitive types."
}
]
}
]
}
}
If I try to use another word such as 'resource' or 'GqlQuery', I get this error:
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"GqlQuery\": Cannot bind query parameter. Field 'GqlQuery' could not be found in request message.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"GqlQuery\": Cannot bind query parameter. Field 'GqlQuery' could not be found in request message."
}
]
}
]
}
}
I can't tell from the API Documentation what my syntax is supposed to be. Can anyone tell me how to compile a functional request body from Apps Script to Datastore?
You need to set the contentType of your payload as well as stringify your JSON payload as follows:
var result = UrlFetchApp.fetch(
'https://datastore.googleapis.com/v1/projects/project-id-5200707333336492774:runQuery',
{
'method':'post',
'contentType':'application/json',
'headers': {authorization: "Bearer " + goa.getToken()},
'payload':JSON.stringify(payload)
}
);
I am new to REST and i am making test cases for server client application. where server is made in php using symphony framework and clients are available both in android and ios. Server implements Rest instead of Soap. Now i have to make a test case in soapui to add a group in which nested JSON parameter is going but i am failed to send parameter as nested. I can show you the request from the log on server side.
[2014-09-24 11:14:36] las_api.INFO:
{
"request": {
"url": "http:\/\/192.168.1.134\/las_web\/web\/app_dev.php\/api\/users\/2\/groups.json",
"attributes": {
"_controller": "Las\\ApiBundle\\Controller\\User\\GroupController::cpostAction",
"_format": "json",
"userId": "2",
"_route": "api_post_user_groups",
"_route_params": {
"_format": "json",
"userId": "2"
}
},
"post": {
"group": {
"name": "Seniors"
},
"token": "{81A9B0D9-CA0E-E70F-ADFF-116EE7A1A980}"
},
"get": [
]
},
"ip": "192.168.1.134"
}
Below is the parameter request parameter. where in group there are two parameters first is name of the group and second is the token generated by server on login time.
{
"group": {
"name": "Seniors"
},
"token": "{81A9B0D9-CA0E-E70F-ADFF-116EE7A1A980}"
}
I have successfully made test case for login. I can show you the request from server log while logging.
[2014-09-24 10:11:37] las_api.INFO:
{
"request": {
"url": "http:\/\/192.168.1.134\/las_web\/web\/app_dev.php\/api\/tokens",
"attributes": {
"_controller": "Las\\ApiBundle\\Controller\\TokenController::cpostAction",
"_format": "json",
"_route": "api_post_tokens",
"_route_params": {
"_format": "json"
}
},
"post": {
"password": "abc123",
"username": "abc#gmail.com"
},
"get": [
]
},
"ip": "192.168.1.134"
}