How to check unwanted parameters in response body in Postman? - api

Refer to the below response body as an example, the only valid parameters of the response body are StatusCode and Message. We can add assertions and easily check if the fields are present with the correct value or not.
Now, I want to check if any unwanted parameters are being populated in the response and make the correction in this case. Is there any way to check this in postman using test assertions?
{
"statusCode": 200,
"message": "Here is the detail message",
"data": "Unwanted parameter"
"UnwantedLink": "www.unwantedlink.com"
}

You can check keys using chaijs
const res = pm.response.json();
pm.test("check keys in response", () => {
pm.expect(res).have.all.keys("statusCode", "message");
})
Example 2 cases below

use json schema validation :
you can use https://www.jsonschema.net/home to generate schema , click setting and settings and set options like:
schema = {
"type": "object",
"properties": {
"statusCode": { "type": "integer" },
"message": { "type": "string" }
},
"additionalProperties": false
};
pm.response.to.have.jsonSchema(schema)

Related

Facebook ads custom audience Data is missing or does not match schema error

i was building a integration with the facebook ads audience API, and according the documentation the request must be created like this:
POST - https://graph.facebook.com/v15.0/<MY_CUSTOM_AUDIENCE_ID>/users?access_token=<MY_ACCESS_TOKEN>
{
"session":{
"session_id":1,
"batch_seq":1,
"last_batch_flag":true,
"estimated_num_total":1
},
"payload":{
"schema":[
"FN"
],
"data":
[
"8b1ebea129cee0d2ca86be6706cd2dfcf79aaaea259fd0c311bdbf2a192be148"
]
}
}
Using the previus example a received a error 400:
{
"error": {
"message": "(#100) Data is missing or does not match schema",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "AqrLd9uIw0D4BBFtHF33bdU"
}
}
For do this i used this documentation https://developers.facebook.com/docs/marketing-api/audiences/guides/custom-audiences#hash
Anyone has use this before?
Your schema field type is array but array use form multi-key qualification.
Change it to string: schema: 'FN'
In docs you can see all formats.
This payload with multi keys work for me:
{
"session": {
"session_id": 123,
"batch_seq": 1,
"last_batch_flag": true
},
"payload": {
"schema": [
"EMAIL",
"PHONE",
"FN"
],
"data": [
["EMAIL_HASH", "PHONE_HASH", "FN_HASH"]
]
}
}

JSON Schema v7: formatMinimum & formatMaximum validate everything

I am using ajv json schema library (v7) and trying to validate a date based on some value. It looks pretty straightforward with using formatMinimum/formatMaximum but it seems that every date is validated when using these keywords
Here's my schema
"some-date": {
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"value": {
"type": "string",
"format": "date-time",
"formatMinimum": "2021-03-10T14:25:00.000Z"
}
}
}
}
}
Here's the json:
{
"some-date": {
"data": {
"value": "2011-03-10T14:25:00.000Z"
}
}
}
Here's how I am validating:
const ajv = new Ajv({allErrors: true})
require('ajv-formats')(ajv)
require('ajv-errors')(ajv)
require('ajv-keywords')(ajv)
const validate = ajv.validate(mySchema)
const isValid = validate(myJSON)
I've tried it on JSONSchemalint and it validates the above json with the given schema. Also, I have tried with several dates and it validates everything.
Please let me know if I am missing something.
Thanks
I'm not sure where you're getting formatMinimum and formatMaximum from, but they are not standard keywords in the JSON Schema specification, under any version. Are they documented as supported keywords in the implementation that you are using?

How to setup Swashbuckle/swagger-ui to render an array of strings as comma-delimited and correctly quoted within a multipart/form-data request?

I am using ASP.NET Core 3.0 (<TargetFramework>netcoreapp3.0</TargetFramework>) and Swashbuckle 5.0.0-rc4 (<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc4" />).
I have an API Controller Action Method which accepts an uploaded file (that is, an IFormFile) and some metadata and tags to associate with the POSTed file:
public async Task<IActionResult> Post(
string fileId = null,
IFormFile file = null,
[FromForm] IDictionary<string, object> metadata = null,
[FromForm] IEnumerable<string> tags = null)
{
// ...
}
I am able -- through sheer luck -- to get Swashbuckle/swagger-ui to send the metadata in a format that seems to be correct (except, I need to write something that will parse out the JSON from within the multipart/form-data fragment). The metadata parameter is OK.
I am having real problems with the tags parameter. The OpenAPI document generated by Swashbuckle is like this:
"/projects/{projectId}/features/imports": {
"post": {
"tags": [
"FeaturesImports"
],
"summary": "Import features from a file uploaded by the end user, or from a file already stored in XXX",
"parameters": [
{
"name": "fileId",
"in": "query",
"description": "The XXX File (Version) Id of the source file to import. Optional; if file is not provided, a fileIdmust be provided.",
"schema": {
"type": "string"
}
},
{
"name": "projectId",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"properties": {
"file": {
"type": "string",
"format": "binary"
},
"metadata": {
"type": "object",
"additionalProperties": {
"type": "object",
"additionalProperties": false
}
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"encoding": {
"file": {
"style": "form"
},
"metadata": {
"style": "form"
},
"tags": {
"style": "form"
}
}
}
}
},
To my eyes, the fact that we have:
"tags": {
"type": "array",
"items": {
"type": "string"
}
seems correct: I want to receive an array of strings.
However, when the swagger-ui renders the form, and the end user enters the required data, the submitted request is not as I would would expect. I would expect the tags data to be something like:
------WebKitFormBoundaryKQWA8MEJTEXgMvsj
Content-Disposition: form-data; name="metadata"
{
"additionalProp1": {},
"additionalProp2": {},
"additionalProp3": {}
}
------WebKitFormBoundaryKQWA8MEJTEXgMvsj
Content-Disposition: form-data; name="tags"
["string1","string2",",","string4\""]
------WebKitFormBoundaryKQWA8MEJTEXgMvsj--
but what I end up getting is:
------WebKitFormBoundaryKQWA8MEJTEXgMvsj
Content-Disposition: form-data; name="metadata"
{
"additionalProp1": {},
"additionalProp2": {},
"additionalProp3": {}
}
------WebKitFormBoundaryKQWA8MEJTEXgMvsj
Content-Disposition: form-data; name="tags"
string1,string2,,string4"
------WebKitFormBoundaryKQWA8MEJTEXgMvsj--
The problems with this are:
the when the data is bound to the Action Method's parameters, the IEnumerable<string> tags parameter only contains one string, and not the 4 I would expect
the individual strings are joined, using a comma; and any commas present in the "raw" strings are not escaped. It is therefore impossible to reconstruct the original intended data
Given the metadata parameter appears to be JSON encoded, I would expect the same for the tags parameter. However, the OpenAPI 3.0.2 spec says (at https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#special-considerations-for-multipart-content) that,
If the property is complex, or an array of complex values, the default Content-Type is application/json
... so that explains the JSON encoding of the metadata parameter, and...
If the property is a primitive, or an array of primitive values, the default Content-Type is text/plain
... ah, and that explains the encoding of the tags parameter, since it is an array of primitive values.
I think the underlying problem is that swagger-ui does not yet support the "Encoding Object" that can be set for multipart parameters, but does anyone have any suggestions, tips, workarounds or other ideas that might be helpful here?

Update Account (PUT) Endpoint in new Yodlee API for MFA

Background
I am using the newer Yodlee Aggregation API that differs from what I was previously building off of.
I am currently using this endpoint in the account registration flow to put the MFA response:
PUT /{cobrandName}/v1/providers/{providerAccountId}
My request looks like this:
{
url: `${this.rest}providers/${providerAccountId}`,
headers: {
'Authorization': `cobSession=${self.appToken}, userSession=${token}`
},
form: {
'MFAChallenge': JSON.stringify(newMfa)
}
}
where this.rest is my personal rest url, providerAccountId is the appropriate providerAccountId for the refresh, self.appToken is the current cobrand session token, token is the current user's login token, and newMfa is a JSON object being stringified that matches this profile:
{
"loginForm": {
"mfaTimeout": 94650,
"formType": "questionAndAnswer",
"row": [
{
"id": "SQandA--QUESTION_1--Row--1",
"fieldRowChoice": "0001",
"form": "0001",
"label": "What is the name of your state?",
"field": [
{
"id": "SQandA_QUESTION_1_1",
"name": "QUESTION_1",
"isOptional": false,
"value": "Enter the answer",
"valueEditable": true,
"type": "text"
}
]
},
{
"id": "SQandA--QUESTION_2--Row--2",
"fieldRowChoice": "0001",
"form": "0001",
"label": "What is the name of your first school",
"field": [
{
"id": "SQandA_QUESTION_2_2",
"name": "QUESTION_2",
"isOptional": false,
"value": "Enter the answer",
"valueEditable": true,
"type": "text"
}
]
}
]
}
with the exeption being the value fields of the field object, which have been encrypted with PKI as per instructions.
Issue
However, when I carry out this PUT request, I get this error from Yodlee:
{ errorCode: 'Y803',
errorMessage: 'MFAChallenge or providerParam required',
referenceCode: 'p1460412835654A4Q24t' }
though I clearly have an MFAChallenge parameter in my form. Any ideas on why I could be getting this error if the MFAChallenge is present (and note that it is the only info that is passed through the PUT request other than through headers or url parameters)? I tried putting it through as body data, but that doesn't seem to work, and very few of the API endpoints actually seem to use body over form encoded strings, though there was at least one.
You have to send this information MFAChallenge as part of URL, see below example
https://developer.api.yodlee.com/ysl/restserver/v1/providers/10114184?MFAChallenge=%7B%20%22loginForm%22%3A%20%7B%20%20%20%20%20%22mfaTimeout%22%3A%2094650%2C%20%20%20%20%20%22formType%22%3A%20%22questionAndAnswer%22%2C%20%20%20%20%20%22row%22%3A%20%5B%20%20%20%20%20%7B%20%20%20%20%20%20%20%20%20%22id%22%3A%20%22SQandA--QUESTION_1--Row--1%22%2C%20%20%20%20%20%20%20%20%20%22fieldRowChoice%22%3A%20%220001%22%2C%20%20%20%20%20%20%20%20%20%22form%22%3A%20%220001%22%2C%20%20%20%20%20%20%20%20%20%22label%22%3A%20%22What%20is%20the%20name%20of%20your%20state%3F%22%2C%20%20%20%20%20%20%20%20%20%22field%22%3A%20%5B%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22id%22%3A%20%22SQandA_QUESTION_1_1%22%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22name%22%3A%20%22QUESTION_1%22%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22isOptional%22%3A%20false%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22value%22%3A%20%22Enter%20the%20answer%22%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22valueEditable%22%3A%20true%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22type%22%3A%20%22text%22%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%20%20%20%20%20%20%20%20%20%5D%20%20%20%20%20%7D%2C%20%20%20%20%20%7B%20%20%20%20%20%20%20%20%20%22id%22%3A%20%22SQandA--QUESTION_2--Row--2%22%2C%20%20%20%20%20%20%20%20%20%22fieldRowChoice%22%3A%20%220001%22%2C%20%20%20%20%20%20%20%20%20%22form%22%3A%20%220001%22%2C%20%20%20%20%20%20%20%20%20%22label%22%3A%20%22What%20is%20the%20name%20of%20your%20first%20school%22%2C%20%20%20%20%20%20%20%20%20%22field%22%3A%20%5B%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22id%22%3A%20%22SQandA_QUESTION_2_2%22%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22name%22%3A%20%22QUESTION_2%22%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22isOptional%22%3A%20false%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22value%22%3A%20%22Enter%20the%20answer%22%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22valueEditable%22%3A%20true%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22type%22%3A%20%22text%22%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%20%20%20%20%20%20%20%20%20%5D%20%20%20%20%20%7D%20%5D%20%7D

Dredd (gavel) : Begin a Json Schema with an array (bug ?)

I am using Markdown for Generate documentation (aglio), generate mocks (api-mock) and check the integrity constraints (dredd).
With Dredd, no problem for check an object, no problem for PUT or POST, but I have a problem with lists.
My lists are arrays, but when I write this schema :
{
"title": "Videos List",
"type": "array",
"items": {
"type":"object",
"required":false,
"properties": {
"id": {
"type": "string",
"required": true
}
},
"required": true
}
}
I get same error all the time: body: JSON schema is not valid! invalid type: object (expected [object Object]/array) at path "/items"
I've tried, again and again, 3 hours, but I failed.
Please help!
PS : sorry for my English, I'm french.
Yes, your data is correct again that schema.
It might be a specific problem of the validator your are using (you did not mention which). You can try to enclose your data with {}. I guess it is expecting allways a JSON like this:
{
[
{
"id": "ninon-retrouve-rudy",
"title": "Ninon retrouve Rudy edited"
},
{
"id": "ninon-retrouve-rudy-1",
"title": "Ninon retrouve Rudy"
}
]
}
Be aware also that your are using Draft03 of Json-schema. I suggest you to use Draft04 (your validator might be obsolete).