Discussions
Unsupported Media Error -- Can we get a simple C# PUT example that uses something other than REST SHARP?
I couldn't resist formatting my question in the Bruce Wilson style (that he hat-tipped back to me. Thanks Bruce ha)...
Can we get a simple C# REST PUT example that does not use REST Sharp. Maybe something that uses HttpClient?
I get Unsupported Media Type no matter what I do. I think it has to do with Encoding or Charset but I don't know which one to send....
This code is the latest I produced to get the Unsupported Media Error
static async Task createEvent(string id)
{
//ZEX18AB197
//ZPEX182820
var settings = new JsonSerializerSettings();
settings.TypeNameHandling = TypeNameHandling.Objects;
// Create the client
using (var client = new HttpClient())
{
// Format headers
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//client.DefaultRequestHeaders.AcceptCharset.Add(new StringWithQualityHeaderValue("UTF8"));
// Request token, and append to headers
await AddTokenToHeaders(client);
EventData eventNew = new EventData();
var responseEvent = await client.GetAsync(baseUrl + EVENT_REST_QUERY + "/" + id);
if (responseEvent.IsSuccessStatusCode)
{
// Deserialize response to DataContract
eventNew = await responseEvent.Content.ReadAsAsync<EventData>();
}
EventFunctionData eventFunction = new EventFunctionData();
eventFunction.Description = "TestFunc3";
eventFunction.EventFunctionCode = "TestFunc3";
eventFunction.EventFunctionId = "TestFunc3";
eventNew.Functions.Add(eventFunction);
string Serialized = JsonConvert.SerializeObject(eventNew);
HttpContent content = new StringContent(Serialized, System.Text.Encoding.Unicode, "application/json");
//byte[] encodedBytes = System.Text.Encoding.UTF8.GetBytes(json);
//System.Text.Encoding.Convert(System.Text.Encoding.UTF8, System.Text.Encoding.Unicode, encodedBytes);
var response = await client.PutAsync(baseUrl + EVENT_REST_QUERY + "/" + id, content);
if (response.IsSuccessStatusCode)
{
// Deserialize response to DataContract
eventNew = await response.Content.ReadAsAsync<EventData>();
}
}
}
This results in a Unsported Media Type error on PUT
Thanks
Posted by Jack Donahue over 4 years ago
REST Endpoint to Authenticate Users
I am looking for the endpoint to authenticate members. I have used this endpoint
https://xxxxxx.imiscloud.com/asi.scheduler_iaei/Token
To receive the token to call REST services. It doesn't appear to work as an endpoint for general users.
Posted by Darrin Jillson almost 5 years ago
REST API Unsupported Grant Type
Hello,
I am trying to request a token so that I can make requests to our instance's API. This is a demo instance of iMIS for our testing purposes. I am getting an error whenever I try to get a token that says the grant type I am passing in is unsupported.
I pass it just as the documentation says. "grant_type" : "password"
I am pretty sure I am trying to access the correct endpoint, I have my:
https://domain.com/token (https://demo.a-gcs.com/sp/token) what it is actually.
I have seen other questions posted adding a "/Asi.Scheduler_XXXX/token" but I am not sure if this is needed for me. How would I go about finding if it was needed, and if it is needed where do I find the information for the XXXX I assume this is some sort of version number?
Our demo instance's version is 20.2.65.9914. I do also want to note I have this request for the token setup in JavaScript and I am using the same jQuery example found here: https://developer.imis.com/reference/bearer-token
I am testing on both the demo site and Postman. The site refreshes a little too quick for me to see other than 400 level error, but in Postman all I get back from a response is
{"error" : "unsupported_grant_type"}
Finally, here is the exact URL I am using. I removed my username and password, but they are there on my end.
https://demo.a-gcs.com/sp/token?grant_type=password&username=******&password=*******
Hopefully that gives you a better picture of my issue. I tried to lay out everything I could. Thanks for any assistance you are able to provide!
Posted by Dustin Branch almost 3 years ago
Getting 405 Error on Party endpoint using Postman/PUT
Hello,
I have a valid Bearer token under the MANAGER account, and I can do GETs all day, but when I try to do the simplest of PUT operations, I'm getting a "The requested resource does not support http method 'PUT'." message.
I'm using GitHub examples from a previous Innovations.
Here are my Raw headers:
{"$type": " Asi.Soa.Membership.DataContracts.PersonData, Asi.Soa.Membership.Contracts",
"PersonName": {
"$type": "Asi.Soa.Membership.DataContracts.PersonNameData, Asi.Contracts",
"FirstName": "Douglas",
"InformalName": "Dougie",
}
I'm using the iMIS demo DB. I've messed around a bunch with the web config, thinking maybe the PUT command was not being preflighted or CORS approved, but everything looks good there.
Also, can anyone help with the derivation of the $type parameter, is it needed/required for PUT requests, where is the value derived from and how do I know if I'm using the proper $type values? I've messed around a bunch with those as well, but no luck.
One other question, is there a reason I can't do a Get from the Organization endpoint? Just 500 errors on that.
I'm using Axios/Vue to create an app, and Axios is also giving me the same error as Postman when trying a Put operation with similar parameters.
Appreciate everyone's help, I'm hoping it's something simple I'm overlooking.
Thanks.
Posted by Bill over 4 years ago
REST API The requested resource does not support http method 'OPTIONS'
I am trying to make a REST API call using AJAX to IMIS using bearer token (which is retrieved using C#) from another site. In other words I am making REST API call to IMIS scheduler endpoint from a different domain.
I know I need to handle the CORS issue so I put in the statements like
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="*" />
....
and stuff like that.
But I am still getting 405 ERROR from the response saying "The requested resource does not support http method 'OPTIONS'".
Does anyone get the same issue and have that resolved successfully ?
Posted by Tim over 4 years ago
REST API: Create User & Password
Is it possible to Create a User and insert a Password for a new contact? If so, can you provide some sample code?
This is actually a follow up to a Curl question posted by Jack.
Posted by Mark Adrion over 4 years ago
How to pass multiple records in REST API POST method?
Hi team,
I would like to create multiple records in my JSON object to insert multiples records at the same time using REST API POST. Is that possible? Please see the example below, which changes I should do in order to add more records (example diff PartyIds)?
Thanks in advance, Chris.
{
"$type":"Asi.Soa.Core.DataContracts.GenericEntityData, Asi.Contracts",
"EntityTypeName":"My_Table_Transactions",
"PrimaryParentEntityTypeName":"Party",
"Properties":{
"$type":"Asi.Soa.Core.DataContracts.GenericPropertyDataCollection, Asi.Contracts",
"$values":[
{
"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts",
"Name":"Card_Number",
"Value":"1111 1111 1111 1125"
},
{
"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts",
"Name":"PartyId",
"Value":"232323"
},
{
"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts",
"Name":"Import_Filename",
"Value":"testFile.csv"
}
]
}
}
Posted by Chris Mazur over 2 years ago
Can we get a simple pure Javascript example of Adding the RequestVerificationToken to headers for GET
Can we get an quick example of GET a Party with Authorization token added to request header in Javascript for demonstration purposes?
Is the Header token key name "RequestVerificationToken" or is it "Authorization"?
Posted by [email protected] about 5 years ago
Access Rest Api from Javascript - CORS exception
Hello, I'm starting to use the Rest Api, but from the begining I'm facing a problem with CORS.
Using javascript I'm able to get the token from https://mysite.com/imis/token
After that, I get the access_token for the subsequent calls, but it I do a simple call to https://mysite.com/imis/api/party/900111 I get this error in my browser Console
"Access to XMLHttpRequest at 'https://mysite.com/imis/api/party/900111' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource."
And this is the JavaScript code I'm trying to execute:
===============================
$.ajax("https://mysite.com/imis/api/party/900111",
{
type : "PUT",
contentType: "application/json",
data: JSON.stringify({ "$type": "Asi.Soa.Membership.DataContracts.PersonData, Asi.Soa.Membership.Contracts",
"PersonName": {
"$type": "Asi.Soa.Membership.DataContracts.PersonNameData, Asi.Soa.Membership.Contracts",
"FirstName": "Peter",
"LastName": "Carlton",
"NamePrefix": "Mr."
},
"PartyId": "900111"}),
dataType: "json",
crossDomain: true,
headers: {
"RequestVerificationToken": response.access_token,
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "x-requested-with"
},
success: function(data){
console.log(data);
}
})
Thank you!
Posted by Leonardo Leme over 2 years ago
Can we get a simple pure C# example of Adding the RequestVerificationToken to headers for GET
(I couldn't resist modeling on Jack's post.)
I'm writing a WebApi which will live outside iMIS, so I'm trying to obtain a token and then send it with a request. No matter what I do, I still get 401 Unauthorized when trying a GET.
First, I created a new Contact "Remote Service" which is a member of the RemoteService role. (I have tried it as public/casual/full -- none seem to make a difference.)
Then I call the /Token endpoint like this.
[code]
var client = new RestClient($"{_baseUri}Token");
var request = new RestRequest(Method.POST);
request.AddParameter("undefined", $"grant_type=password&username={_imisLogin}&password={_imisPassword}", ParameterType.RequestBody);
[/code]
I get a valid response that contains a valid (looking) access_token. I use it like this:
[code]
var client = new RestClient(_baseUri);
var request = new RestRequest(Method.GET);
request.AddHeader("RequestVerificationToken", token);
request.Resource = $"api/user?UserName=Equal:{username}";
IRestResponse<ImisTypes.UserData> response = client.Execute<ImisTypes.UserData>(request);
if (response.StatusCode == HttpStatusCode.Unauthorized)
{
// FAIL
}
[/code]
Even though all operations require the RequestVerificationToken, none of them show how to include it.
Posted by Bruce Wilson about 5 years ago