GET with body (json format), what to do with apostrophe? - rest

I am new to REST. I have a client who tries call an api I have running. Problem is that they use some type of builder to create the body.
In my endpoint, I expect name field in the body like this:
{
"name": [
{ "tag": "1", "value": "O'Bryan" },
...
But client sends something like this:
{
'name': [
{'tag': '1 ', 'value': 'O'Bryan'}
It works except when name has apostrophe. I am wondering if this body will still valid. If not, what can they do to fix it without using double quote(")?

This body will not be valid, you would need to escape the single quote like so \'

Related

Http with Azure AD - Graph API - POST Method - Powerapps

I'm not able to send a POST or PATCH action thru the connector because I can't figure out how to compose the body correctly.
I try it that way:
But I get this error:
I try it without brakets, with more brakets, with single, double and without quotations but it seems nothing works.
Please can anyone tell me how to compose the body in the right way?
Thx!
Look like the body is not a valid json. Properties givenName, surname, etc. should be wrapped by quotes.
{
"givenName": "Microsoft",
"surname": "Graph",
"emailAddresses": [
{
"address": "Microsoft.graph#api.com",
"name": "Microsoft Graph"
}
],
"businessPhones": [
"+334100100"
],
"mobilePhone": "+9857665765"
}

How to get a xml attribute variable (type double) using xPath in response using Wiremock

Request is an xml like this:
<Request>
<Account>373953192351004</Account>
<Amount>98.21</Amount>
</Request>
Response is a json and should have amount mapped from request but data type being a decimal number (not String) e.g.
{
"response": {
"status": "SUCCESS",
"amount": 98.21
}
}
i was able to do it with xPath using json mapping like this:
"amount": "{{xPath request.body '/Request/Amount/text()'}}"
but above xpath makes amount a string with double quotes in the response, like:
"amount": "98.21"
How do i make it without quotes like:
"amount": 98.21
note: I can't remove the quotes in "{{xPath... as it wouldn't be a valid json anymore.
You need to remove the double quotes from outside the {{ xPath ... }}. So:
"amount": {{xPath request.body '/Request/Amount/text()'}}

Passing multiple json as a payload for a request in Gatling

sample json payload:
'{
"Stub1": "XXXXX",
"Stub2": "XXXXX-3047-4ed3-b73b-83fbcc0c2aa9",
"Code": "CodeX",
"people": [
{
"ID": "XXXXX-6425-EA11-A94A-A08CFDCA6C02"
"customer": {
"Id": 173,
"Account": 275,
"AFile": "tel"
},
"products": [
{
"product": 1,
"type": "A",
"stub1": "XXXXX-42E1-4A13-8190-20C2DE39C0A5",
"Stub2": "XXXXX-FC4F-41AB-92E7-A408E7F4C632",
"stub3": "XXXXX-A2B4-4ADF-96C5-8F3CDCF5821D",
"Stub4": "XXXXX-1948-4B3C-987F-B5EC4D6C2824"
},
{
"product": 2,
"type": "B",
"stub1": "XXXXX-42E1-4A13-8190-20C2DE39C0A5",
"Stub2": "XXXXX-FC4F-41AB-92E7-A408E7F4C632",
"stub3": "XXXXX-A2B4-4ADF-96C5-8F3CDCF5821D",
"Stub4": "XXXXX-1948-4B3C-987F-B5EC4D6C2824"
}
]
}
]
}'
I am working on a POST call. Is there any way to feed multiple json files as a payload in Gatling. I am using body(RawFileBody("file.json")) as json here.
This works fine for a single json file. I want to check response for multiple json files. Is there any way we can parametrize this and get response against multiple json files.
As far as I can see, there's a couple of ways you could do this.
Use a JSON feeder (https://gatling.io/docs/current/session/feeder#json-feeders). This would need your multiple JSON files to be in a single file, with the root element being a JSON array. Essentially you'd put the JSON objects you have inside an array inside a single JSON file
Create a Scala Iterator and have the names of the JSON files you're going to use in it. e.g:
val fileNames = Iterator("file1.json", "file2.json)
// and later, in your scenario
body(RawFileBody(fileNames.next())
Note that this method cannot be used across users, as the iterator will initialize separately for each user. You'd have to use repeat or something similar to send multiple files as a single user.
You could do something similar by maintaining the file names as a list inside Gatling's session variable, but this session would still not be shared between different users you inject into your scenario.

Retrieve UserName from ServiceNow

I am able to retrieve records for a particular Incident ID using Invoke-RestMethod. However, while retrieving the data, values like Resolved To, Updated By, etc. get populated by a sysid.
Resolved By comes in this format:
https<!>://devinstance.servicenow.com/api/sysid, value= sysid
I would like to view the username instead of the sysid.
The 'User ID' (user_name) isn't on the Incident, it's on the sys_user table, so you'll have to dot-walk to it.
If you're using the table API, you'll need to specify a dot-walked field to return, using the sysparm_fields query parameter.
This is no problem, just specify your endpoint like this:
$uri = "https://YOUR_INSTANCE.service-now.com/api/now/table/incident?sysparm_query=number%3DINC0000001&sysparm_fields=resolved_by.user_name"
I've specified a query for a specific incident number is requested, but you can replace that with whatever your query is.The important part is sysparm_fields=resolved_by.user_name. You'll want to specify any other fields you need here, as well.
The JSON I get as a result of running this API call, is the following:
{
"result": [
{
"resolved_by.user_name": "admin"
}
]
}
Note the element name: "resolved_by.user_name".
Another option for doing this, would be to tell the API to return both display, and actual values by specifying the sysparm_display_value parameter and setting it to all to return both sys_id and display value, or just true to return only display values.
Your URI would then look like this:
https://dev12567.service-now.com/api/now/table/incident?sysparm_query=resolved_byISNOTEMPTY%5Enumber%3DINC0000001&sysparm_display_value=all
And your JSON would contain the following:
"number": {
"display_value": "INC0000001",
"value": "INC0000001"
},
"resolved_by": {
"display_value": "System Administrator",
"link": "https://YOUR_INSTANCE.service-now.com/api/now/table/sys_user/6816f79cc0a8016401c5a33be04be441",
"value": "6816f79cc0a8016401c5a33be04be441"
},
"sys_updated_by": {
"display_value": "admin",
"value": "admin"
},
This would be accessed by:
answer.result[n].resolved_by.display_value

Delphi XE5: Problems with proper visualization of extracted GMail emails

I am facing some trouble in properly visualizing emails extracted from GMail. I use the GMail API to retrieve the messages. This part seems to be working properly and I get the json with the entire message.
Here is a small part of one of the body parts
"mimeType": "multipart/alternative",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "multipart/alternative; boundary=001a114710d029267205278f13b9"
}
],
"body": {
"size": 0
},
"parts": [
{
{
"partId": "0.0",
"mimeType": "text/plain",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/plain; charset=UTF-8"
},
{
"name": "Content-Transfer-Encoding",
"value": "quoted-printable"
}
],
"body": {
"size": 549,
"data": "SGkgUGF1bCwNCg0KQXBvbG9naWVzLCBidXQgSSBmb3Jnb3QgdG8gbWVudGlvbiB0aGF0IHRoZSByZXN0IG9mIHlvdXIgb3JkZXIgaGFzIGJlZW4NCnNlbnQgb3V0IGluIHRoZSBtZWFudGltZQ0KDQpNYW55IHRoYW5rcw0KDQoqS2luZCBSZWdhcmRzKg0KKkJhcmJhcmEgSm9uZXMqDQoqSW50ZXJuZXQgU2FsZXMqDQoNCipPbGQgTWlsbCBTYWRkbGVyeSoNCg0KKnd3dy5zYWRkbGVyeS5iaXogPGh0dHA6Ly93d3cuc2FkZGxlcnkuYml6Lz4qDQoNCipUZWw6ICs0NCAoMCkyOCA5MzM1IDMyNjggPCUyQjQ0JTIwJTI4MCUyOTI4JTIwOTMzNSUyMDMyNjg-Kg0KDQoqVGFrZSBhIFZpcnR1YWwgdG91ciBvZiBvdXIgc2hvcCoNCkdvb2dsZSBwbGFjZXMgaHR0cDovL2dvby5nbC85Y1o5ZDANCipbaW1hZ2U6IElubGluZSBpbWFnZXMgNF1XaXNoaW5nIHlvdSBhIHZlcnnigItbaW1hZ2U6IElubGluZSBpbWFnZXMgM10qDQoqICAgICAgICAgICAgICAgICAgTWVycnkgQ2hyaXN0bWFzKg0KDQoq4oCLICAg4oCLICDigIsgICAgW2ltYWdlOiBJbmxpbmUgaW1hZ2VzIDJd4oCLKg0K"
}
}
So what is the data part encoded with? I am getting confused with the "Content-Transfer-Encoding" ->"quoted-printable". Should I decode the value of the data using a "quoted-printable" decoder or not?
Initially without noticing the "quoted-printable" value, I decoded the data value using DecodeBase64, here is how I am making it
function TViewEmailsForm.DecodeData(aStr: String): String;
var
aStrm: TBytesStream;
aStrStrm: TStringStream;
begin
Result := '';
if aStr = '' then
Exit;
aStrm := TBytesStream.Create(DecodeBase64(aStr));
aStrStrm := TStringStream.Create;
try
aStrm.Position := 0;
aStrStrm.LoadFromStream(aStrm);
Result := aStrStrm.DataString;
finally
aStrm.Free;
aStrStrm.Free;
end;
end;
Using that returns human readable text, however at the end something more is decoded and I don't get what it is. I presume it is some kind of formatting bold text, link, kind of signature but I don't succeed in anyway to show it properly (not sure what to use though as component - RichEdit, HTMLViewer)
The end of the decoded string looks like
.......
*Name of the company*
*website of the company <again the website of the company>*
*Tel: +44 (0)28 9335 3268 <%2B44%20%280%2928%209335%203268
ѓBѓBЉ•ZЩHHљ\ќX[Э\€Щ€Э\€ЪЬ
ѓB‘ЫЫЩЫHXЩ\И‹ЛЩЫЫЛ™ЫОXЦЋYBЉ–Ъ[XYЩN€[›[™H[XYЩ\И
UЪ\Ъ[™И[ЭHH™\ћx "ЦЪ[XYЩN€[›[™H[XYЩ\ИЧJѓBЉ€Y\њћHЪљ\ЭX\КѓBѓBЉё "И8 "И8 "ИЪ[XYЩN€[›[™H[XYЩ\И—x "КѓB›
I have some other messages which pretend to have html body, but again the data is seen in that way. I tried to load this string into the lines of TRichEdit, but had no luck, I tried to use TIdDecoderQuotedPrintable to decode this string, though I am not sure if I have to make it, but some of the characters got replaced by '?' (question marks)
What I am missing here and what is the proper way of visualizing the content of the messages?
After serious research and testing different encoders/decoders I finally managed to properly decode what was encoded in the message.
I used Indy's TIdEncoderMIME found in IdCoderMIME and used the DecodeString method. The HTML messages and bodies are properly decoded too with it.
Hope this will help other people not to spend two days in "fighting" with decoding messages!
EDIT: I noticed that the symbol > comes as ? Maybe there something else which has to be done?
EDIT2: It seems that the encoding of the data is not actually Base64 but Base64Url. On the following link http://blog.marcocantu.com/blog/delphi_facebook_base64_encoding.html you can find interesting post on that. The images are encoded in that way and the standard decoding doesn't work for extracting them.
Whoever knows French can read something here too http://codes-sources.commentcamarche.net/source/51156-base64-base64url-encode-decode