07-22-2019 07:36 AM - edited 07-23-2019 04:29 AM
Dear community,
I come across some issues when I'm trying to use a POST or PATCH request on my data using the REST API.
The POST request (see screenshot) returns a 405 error. The payload is given and correct, yet the server doesn't seem to allow this action to be performed. Something similar could be said when I'm trying the same operation using a PATCH (403). My guess for the PATCH is that it refuses due to patch not being included in the Access-Control-Allow-Methods of the response headers.
GET methods are working correctly, so I wonder where the problem is located. I have added my script for the POST method below, maybe there is a problem in there (Note: working with credentials give the same result).
My question is whether this is a backend server issue, or whether my script is missing something. We've had a backend issue before, yet I (as a intern) do not have access to the backend. The previous problem was discussed by my colleague in this post:
Script:
Thanks in advance,
Reinier
07-24-2019 06:38 AM
Hi Reinier,
Can you "play" the actual POST request using e.g. Postman, Fiddler, or similar tools?
When looking at the code - at least, there are wrong apostrophes in the url parameter - are you sure they're correct in your original code? (`` instead of ' ')
Also, it seems to me like you're trying to call POST http://orions/erdas-apollo/content/catalog/items/${context.state.activeDataset.id}
But there's no such method allowed in the REST API, I can see only DELETE, GET and PATCH...
Jan
07-25-2019 01:14 AM - edited 07-25-2019 02:47 AM
Hello Jan,
First of all thanks for replying to me.
Before I wanted to answer you, I wanted to check a few things including the topics you mentioned as potential problems.
Thanks for your help so far.
With regards,
Reinier de Graaf
07-25-2019 01:19 AM
Hi Reinier,
Do you supply the "propertyName" value? It is required for the POST call you mentioned.
07-25-2019 01:33 AM
In the API console, I can not get anything to work using any propertyName. This means I also can not get a functioning request URL to use in my script.
What I've tried to do in my script was to change a value of the 'active dataset' (a state in Vuex) and 'POST' the changes. It showed in the pictures (1st post) a payload containing the change. I'm not sure 100% sure if that's the right behaviour.
07-25-2019 05:11 AM
I've just found out that the POST /content/catalog/items/{ID}/{propertyName} only apply to the following catalog item details:
"properties": {
"apollo.connector": "com.erdas.apollo.hedm.connector.ImageryConnector"
}
Which isn't probably what you're looking for.
If you want to change standard data set properties, rather use PATCH /content/catalog/items/{ID} with proper payload, e.g.:
PATCH /content/catalog/items/{ID} payload: { "title": "atl_tiles_4_1.ecw" }
07-25-2019 05:28 AM
Hey Jan,
That would explain why the POST request isn't generating anything in my script, Postman and the API console. I'll continue trying it with PATCH, which works in the API console and Postman.
My assumption that the PATCH request isn't working due to PATCH not being listed in the Access-Control-Allow-Method of the response header, also doesn't seem to be the case. This because it does work in Postman without it.
Greetings,
Reinier
07-25-2019 05:48 AM
Maybe it has something to do with this:
https://stackoverflow.com/questions/43206233/vue-js-patch-method-not-allowed
https://github.com/pagekit/vue-resource/issues/576
08-09-2019 02:21 AM - edited 08-09-2019 02:38 AM
Hello,
A small update on the progress.
Patching finally works. I can change the values of some of my properties and patch them to the Apollo server. However I have one current issue remaining which is trying to change true values to false and vice versa.
I've used the API to do this:
{ "acquisitionInfo": { "dataAcquired": "true" } }
Opening the Chrome console during the process of the API I get a correct 204 status code and see the following payload:
{acquisitionInfo: {dataAcquired: "true"}} acquisitionInfo: {dataAcquired: "true"} dataAcquired: "true"
When trying to do the same patch from my own made editor. I do the exact same thing, I do get the exact same payload, yet the response headers are not showing up. I also get the following CORS related error.
Access to XMLHttpRequest at 'http://orions/erdas-apollo/content/catalog/items/4028828a6ab522ff016ab5eb6e49007d' from origin 'http://localhost:8084' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
store.js:125
No changes found Error: Network Error
at createError (createError.js:16)
at XMLHttpRequest.handleError (xhr.js:69)
xhr.js:160 PATCH http://orions/erdas-apollo/content/catalog/items/4028828a6ab522ff016ab5eb6e49007d net::ERR_FAILED
dispatchXhrRequest @ xhr.js:160
The error is not new. Despite CORS issues, I was always able to patch my names and dates. The displayed error of no changes found is technically incorrect. The current problem however is that for boolean fields, the changes don't work at all.
Is there any specific reason that this is only happening for properties with boolean values? (It also works in Postman)
With regards,
Reinier,
08-09-2019 04:05 AM
Do you have CORS headers properly configured on the APOLLO server as it was discussed in the linked Community thread above?
Also, the boolan values shouldn't be double-quoted ("true" instead of true). It may be improperly understood by JSON parsers.