The value 'AddOrder' is not valid - asp.net

I created a catalog api using asp.net core and cosmos db .I post a catalog data set. but i get following error.I debug it using break points the problem is my result body is null.
{"errors":{"id":["The value 'AddOrder' is not valid."]},"title":"One or more validation errors occurred.","status":400,"traceId":"80000011-0005-fe00-b63f-84710c7967bb"}
Catalog controller code example
Catalog repository code example
azure cosmos db structure :
What am i doing wrong ??
post json file :
{
"Id": 1,
"venderId": 1,
"IndustryName": "dsa",
"ProductName": "sad",
"CurrentQuantity": 1,
"Tag": "sad",
"Unit": "dsad",
"Price": 34,
"Class": "dsfs",
"category": {
"Id": 1,
"Name": "freg",
"Description": "fdf",
"subcategory": [
{
"Id": 1,
"Name": "ergt",
"Description": "erfwef"
}
]
}
}

Your controller code is validating the Model and returning the BadRequest: https://github.com/kajasumanie/calalogapi/blob/master/CalalogAPI/Controllers/BooksController.cs#L41
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
The error you are seeing is unrelated to Cosmos DB, whatever payload you are sending is not valid for the Catalog class.
That class is not available in your repo, so it's hard to say. You should check the payload versus the model class and verify the format and requirements are met.

I indicate the Id as Guid value. When try to add the order, I gave the id value as 1,2,3....
But Guid value I need to pass the Id value like 80000011-0005-fe00-b63f-84710c7967bb.
That is the problem .

Related

AWS AppSync GraphQL query a record by a field value

I have an user table, which consists of email, phone etc., and I would like to query a record based on its email or phone value (instead of #Id). Having not-adequate knowledge to do this - I wrote a schema like this:
type Query {
...
getUser(id: ID!): User
getUserByEmail(input: GetUserByEmailInput!): User
...
}
input GetUserByEmailInput {
email: String!
}
In resolver against getUserByEmail(..), I tried to experiment but nothing worked so far, so its remain to default state:
So when I ran a query like this to the Queries console:
query GetUserByEmail {
getUserByEmail(input: {email: "email#email.com"}) {
id
name
email
image
}
}
this returns an error like this:
{
"data": {
"getUserByEmail": null
},
"errors": [
{
"path": [
"getUserByEmail"
],
"data": null,
"errorType": "DynamoDB:AmazonDynamoDBException",
"errorInfo": null,
"locations": [
{
"line": 41,
"column": 5,
"sourceName": null
}
],
"message": "The provided key element does not match the schema (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: xxx)"
}
]
}
How can I query a record by non-Id field value?
If you use the Create Resources flow in the console, it will create a listUsers query that looks like the following for example. Note that the DynamoDb operation will be a Scan that has a DynamoDb filter expression where you can use any field to query DynamoDb. See below for the mapping template.
{
"version": "2017-02-28",
"operation": "Scan",
"filter": #if($context.args.filter) $util.transform.toDynamoDBFilterExpression($ctx.args.filter) #else null #end,
"limit": $util.defaultIfNull($ctx.args.limit, 20),
"nextToken": $util.toJson($util.defaultIfNullOrEmpty($ctx.args.nextToken, null)),
}
You can find more details about Scans and filter expressions in the AWS AppSync documentation:
https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-dynamodb-resolvers.html

How can we log Custom Activity data against leads with Marketo REST API?

We have created a Custom Activity with Marketo web portal, and we are able to create leads with REST API. So now, how can we log Custom Activity data using Marketo REST API?
Custom Activity structure is as follows:
{
"id": 100001,
"name": "TEST_ACTIVITY",
"apiName": "test_api_c",
"description": "",
"primaryAttribute": {
"name": "event_id",
"apiName": "event_id",
"dataType": "string"
},
"attributes": [
{
"name": "email",
"apiName": "email",
"dataType": "email"
},
{
"name": "event_data",
"apiName": "event_data",
"dataType": "string"
}
]
}
You can push your custom activity records to the Add Custom Activities endpoint, which is available at the POST /rest/v1/activities/external.json url.
First, worth to note, that in order to use the endpoint, the API user has to have the “Read-Write Activity” permission.
The endpoint expects a payload with a single input key, that can hold up to 300 activity records. For each activity record the leadId, activityDate, activityTypeId, primaryAttributeValue and attributes fields are required, and in case of the attributes array, the name is the normal “name” field, not the “apiName”.
In your case the payload would look something like this:
{
"input":[// Note the array of records
{
"activityDate":"2018-03-20T22:43:12+02:00",
"activityTypeId":100001,
"leadId":<LEAD_ID>,
"primaryAttributeValue":"<YOUR_EVENT_ID>",
"attributes":[
{
"name":"email",// This is the `name` field of the attribute, not the `apiName`!
"value":"<EMAIL_ADDRESS>"
},
{
"name":"event_data",// This is the `name` field of the attribute, not the `apiName`!
"value":"<EVENT_DATA>"
}
]
},
//{
// …other activity records…
//}
]
}

How to safely test WooCommerce api key acces rights?

For an application I'm building I would like to test if I have both read and write access on the customerkey, customersecret combination I receive.
Is there a specific function which is the least disrupting for testing write access? Or is creating and removing a product the adviced way to go?
You can try to create a Tax Class with missing fields. You'll get a validation error if the consumer key has write permission, vs an authorization error if it doesn't.
{
"code": "rest_missing_callback_param",
"message": "Missing parameter(s): name",
"data": {
"status": 400,
"params": [
"name"
]
}
}
vs
{
"code": "woocommerce_rest_authentication_error",
"message": "The API key provided does not have write permissions.",
"data": {
"status": 401
}
}

Passing a Dictionary object as part of a request on ServiceStack Swagger

I'm currently working with ServiceStack's Swagger plugin and I'm having trouble populating certain objects in my request, specifically Dictionary objects.
In the image below, I want to pass a Dictionary<string,string> object as JSON for FieldFilter. What is the format for this? I've tried several examples but the FieldFilter object is always being deserialized as null.
UPDATE
I've taken a look at the JSON example provided in this link:
http://www.newtonsoft.com/json/help/html/SerializeDictionary.htm
which shows that a Dictionary<string,string> JSON representation is as follows:
{
"James": "9001",
"Jo": "3474",
"Jess": "11926"
}
but the result is still deserialized to null. I think this is more a limitation of ServiceStack and the Swagger plugin. I'll take on the suggestion of using a list of classes instead and provide another update
UPDATE 2
I've tried creating a FieldFilter class (which contains two string properties). This is the JSON I'm entering now:
{
"FieldId": "1",
"Value": "Hello"
},
{
"FieldId": "2",
"Value": "Goodbye"
}
Trying this (and other slight variations) the field is still being deserialized as null.
As a test, I added the field filter object to my CreateUser request, which has a single body with all the fields required. The JSON for that looks like this:
{
"FieldFilter": [
{
"FieldId": "1",
"Value": "Hello"
},
{
"FieldId": "2",
"Value": "Goodbye"
}
],
"FirstName": "",
"LastName": "",
"Password": "",
"Permissions": [
""
],
"Roles": [
""
],
"Username": ""
}
Now in this example where all the fields are in one JSON request, the FieldFilter field is deserialized with the correct values! Is there a reason why it works here? Am I missing something painfully obvious?

No HTTP resource was found that matches the request URI (...) for all tables

Following this tutorial as a guide (OData/EntityFramework/Asp.Net).
I'm able to execute a simple GET command on the root.
{
"#odata.context": "http://localhost:49624/$metadata",
"value": [
{
"name": "Appointments",
"kind": "EntitySet",
"url": "Appointments"
},
......
{
"name": "Clients",
"kind": "EntitySet",
"url": "Clients"
}
]
}
But anything more complex than that gives me an error message. (I'm using a null routePrefix.)
http://localhost:49624/Services
Gives me:
{
"Message": "No HTTP resource was found that matches the request URI 'http://localhost:49624/Services'.",
"MessageDetail": "No type was found that matches the controller named 'Services'."
}
Here's my super simple GET
[EnableQuery]
public IQueryable<Service> Get()
{
return db.Services;
}
If it matters I'm using Postman to test these commands. Although I imagine that is a non-factor.
I have a database & a DbSet for every table. I have no idea why I can't access any of this.
WebApiConfig:
config.MapHttpAttributeRoutes();
ODataModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Appointment>("Appointments");
builder.EntitySet<Service>("Services");
builder.EntitySet<Employee>("Employees");
builder.EntitySet<Client>("Clients");
config.MapODataServiceRoute(
routeName: "ODataRoute",
routePrefix: null,
model: builder.GetEdmModel());
I'm sorry if this is a basic question but I'm really new to all this and have been at this wall too long already haha.
Jan Hommes above pointed out above that the controller class needs to be pluralized (In my case ServiceController -> ServicesController)

Resources