postman giving 400 bad request when i use global varibales how to solve this - api

when i use normal json body postman gives me 201 created response but when i am using global variable postman giving me 400 bad request

Variables still need to be used in proper JSON format therefore you should be putting your strings in quotes:
{
"email": "{{email}}",
"password" : "{{password}}",
"confirmpassword" : "{{confirmpassword}}"
}
See https://learning.postman.com/docs/sending-requests/variables/
Side note: please provide actual "happy path" (when it worked) as well as your errors. Text instead of images is good too to help people try to reproduce your errors without a lot of typing

Related

Why is axios returning a different responseURL than the request url?

I am making an Axios GET request from my React Native app to my locally served backend.
The response "config" object shows a "baseURL" of "http://192.168.1.68:8080/api" and a "url" of "inventory?status=ALL&barcode=127035838".
The response "request" object shows a "_url" of "http://192.168.1.68:8080/api/inventory?status=ALL&barcode=127035838".
However! the response "responseURL" attribute shows a value of "http://192.168.1.68:8080/api/inventory?status=ALL&barcode=127035838%1D".
The request from the app is not finding the barcode, returning 204. Making the same request from Postman, I am able to find the barcode with a 200 status. This makes me believe the issue is not on the backend. I switched from Axios to fetch and found the same result.
It is my guess the additional "%1D" on the end of the barcode is the cause of frustration. Why is the rsponseURL different from the request url. Why is axios adding "1%D", and how can I make it stop? Is there something else going on?
My solution:
let uriSN = serialNumber;
uriSN = encodeURIComponent(serialNumber);
uriSN = uriSN.replace('%1D', '');
Encoding the barcode and then stripping it of the "1%D" solves the issue. I do not know if it is the best or complete solution.
%1D is the url-encoded hex for 29 which is an ASCII control character called the "group seperator" so your serialNumber might have this character which is being parsed accordingly (by design) through the encodeURIComponent function. This is known as "GIGO" (garbage in garbage out).

Invalid request body error when sending json string as data to an external api using CL_HTTP_CLIENT

We are facing an issue while sending json data to an external api using CL_HTTP_CLIENT.
The JSON data is produced using '/ui2/cl_json=>serialize( data = ls_body compress = abap_true pretty_name = /ui2/cl_json=>pretty_mode-camel_case )' .
when sending this JSON as data the the external api returns status 400 with response as
{ "errorCode": "INVALID_REQUEST_BODY", "message": "The request body is missing or improperly formatted. Unexpected character encountered while parsing value: \u001f. Path '', line 0, position 0." } .
we also stringyfied this JSON Data in backend as it might be due to parsing error but it didnt work.
The same stringyfied data tried to send through browser console using ajax and it did worked without any issue.
could any any one tell us how to handle this json object and send this to external api using CL_HTTP_CLIENT.
Note : JSON STRING is deeply nested .
Thanks in advance..
You can use request catcher service for getting SAP output.
Then check your output has valid json.
Check external api with rest tool like postman or SoapUI. Every developer not track guidliness may be external api has limitations.
The issue was with the unicodes in the string.
these were not accepted by the external api so removed from the string and sent to api and it did worked.
Thanks for You suggestion.

Google Sheet API batchUpdateByDataFilter PHP Function

https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchUpdateByDataFilter
We have used above function in our code, while we are passing the more than 50 or 100 records within the array records then given 400 bad request array in response.
Can anyone describe the limit of the total values that we are going to pass within the above function?
Here is my code:
$batchupdate = array("valueInputOption" => "RAW", "data" => $dataarray);
try {
$requestBody = new Google_Service_Sheets_BatchUpdateValuesByDataFilterRequest($batchupdate);
$response = $service->spreadsheets_values->BatchUpdateByDataFilter($spreadsheetId, $requestBody);
}
catch(Exception $e) {
echo 'Message: ' . $e->getMessage();
}
Troubleshooting:
Problems with the Request
Until you attach a sanitized version of your Request body we cannot be sure about the root-cause of the problem you are facing.
However, an error 400 means that the request you did is invalid. So, most likely, the problem is in that.
Check if your request object is formatted as detailed on the documentation.
Problems with the Client
If you are able to use the Try this API sidebar with the same Request Body then it could be related to the PHP client.
Note: This is language independent. Create a JSON Object that has the same structure as your request body.
If that's the case, we will need to see more of your code to verify that you are not using your valid Request body in an invalid way (eg. sending it encapsulated in another object).
By referencing the PHP Library documentation you can see the properties of the objects you can use.

Can I include the all JSON paths required in a JSON file and use it inside my feature file for match or anything else?

For eg, I save paths.json and add the following. I know there is a mistake in the way i try, but not able to find it
{
"name": "JSON Path's",
"description": "This mainly store the paths of the JSON elements which are validated in each scenario",
"SC_4": {
"appHeader": "$.testResponse.applicationHeader",
"ProductsAction": "$.testResponse.applicationHeader.item.action"
}
}
* def attributes = read('../jsonpaths/paths.json')
Given url endPointURL
And request baseJsonRequest
When method post
Then status 200
* def appHeaderSecondTry = attributes.SC_4.appHeader
* print appHeaderSecondTry
Wow you are getting to be a power user of Karate so soon :P
Okay, personally I don't recommend trying to build a mini-framework over Karate like you are doing, I can see what you are trying to do - keep all assertions "declarative" and try to re-use common code for the actual HTTP call etc.
My opinionated take on this is, you save very few lines of code (because of how easy it is to make an HTTP request in Karate). Also, you should be able to re-use a feature file via the call keyword. I would urge you to try and keep the match statements "normal" in your tests.
That said, what you are missing is the karate.eval() operation, look for it in the doc. Here is an example (line 91): js-arrays.feature

How to retrieve a list of all articles of Fogbugz-wiki that have a certain tag?

Via the Fogbugz REST API I try to get all articles with a certain tag. I wrote some code in python to get it but I got "zero" as result. Here is my code:
import requests
...
some code to log in
...
req_params={"cmd": "search", "token": self.token,"q":"tag:\"my_cool_tag\""}
response = requests.get(req_url, data=req_body, headers=req_header, params=req_params, verify=False)
print (response.text)
as response I got:
...cases count="0"...
Is there a way to get all articles with a certain tag in a list via REST-API and how I can achieve this?
I am using FogBugz Version 8.8.49.0.
Try the search with curl or directly in your web browser to check that it works, then see if you can debug your Python.
In a browser I can successfully query FogBugz Online with something like:
https://<domain>.fogbugz.com/api.asp?token=<token>&cmd=search&q=tag:%22<my_tag>%22
Although I entered quotes around my tag, the browser url encoded them to %22. Obviously <domain>, <token> and <my_tag> should be replaced with your own values.
Your basic parameters look OK, but I haven't used Python so am not sure whether escaping the quotes around the tag translates well to the GET request? Maybe try url encoding "my_cool_tag".