I need to update a Podio item field value via AJAX call from an external app that I have built. I was able to complete the first part of the process - getting the OAuth token - but I'm having trouble figuring out how to form the PUT
request follow-up...
Here's what I've got going so far:
$.ajax({
type:'POST',
url:'https://podio.com/oauth/token',
data: {
'grant_type': 'app',
'app_id': '1234',
'app_token': '1234',
'client_id': 'myidcode',
'redirect_uri': 'redirect.com',
'client_secret': '1234secret4321'
}
}).done(function(response){
$.ajax({
type:'PUT',
url:'https://api.podio.com/item/${item_id}/value/${field_id}',
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'OAuth2 ' + response.access_token)
},
data: {
values: "doofus@test.com"
}
}).done(function(){
console.log("Ok!")
})
})
The first AJAX call is successful - I get my auth token back in the response. However, the second AJAX call results in the XMLHttpRequest cannot load https://api.podio.com/item/1/value/142236262. Response for preflight has invalid HTTP status code 400
error.
I'm sure this is a simple solution and I'm so close to accomplishing what I need to to... any clarification on the PUT
call would be much appreciated. Perhaps the url is not correct?
Note The Podio docs offer some insight into this step:
'All of these authentication methods will provide you with an access token. You will be including this access token in any subsequent requests to the API. You will do this by including an HTTP header with the access token like so: Authorization: OAuth2 ACCESS_TOKEN Where ACCESS_TOKEN should be replaced with the actual access token you have obtained.'
Setting the AJAX headers like so:
headers: {
'Authorization': response.access_token
}
or
headers: {
'Authorization': 'OAuth2 ' + response.access_token
}
results in the preflight error as well.
The first part of my problem was that this request needed to originate from https. Once I cleared that up, the other issue was that I had forgotten to set the content-type.
$.ajax({
type:'PUT',
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'OAuth2 ' + response.access_token)
},
contentType: 'application/json',
url:'https://api.podio.com/item/654321/value/12345',
data: JSON.stringify({'value': 'new_value'})
}).done(function(response){
console.log(response)
}).fail(function(error){
console.log(error)
})
That patched it up.