PATCH not working. Get 401 error.
dpatel20
Registered Users Posts: 3 Beginner grinner
I'm using smugmug API and trying to send a patch request to update an album's password. The below code is a quick trial using Javascript. I use the ddooauth library here : from Github (I can't post links) github / ddo / oauth-1.0a.
It works fine for a GET request but as soon as I try to do a PATCH request it gives me an error 401 (unauthorised). I think I am doing something wrong with the way I form the request. Do the parameters (i.e. the password field and new password) need to be part of the signature hash or should it be separate?
<CODE>
// Initialize
const oauth = OAuth({
consumer: {
key: 'consumer_key',
secret: 'secret'
},
signature_method: 'HMAC-SHA1',
hash_function(base_string, key) {
return CryptoJS.HmacSHA1(base_string, key).toString(CryptoJS.enc.Base64);
}
});
const request_data = {
url: 'ht tps :// api.smugmug.com / api / v2 / album / xhXXXX',
method: 'PATCH',
data: {Password: "temp123"} // Should this be here??
};
// Note: The token is optional for some requests
const token = {
key: 'key',
secret: 'access_token'
};
function loadDoc() {
console.log(oauth.authorize(request_data, token))
$.ajax({
url: request_data.url,
type: request_data.method,
headers: {
Accept : "application/json",
'Content-Type' : 'application/json'
},
data: oauth.authorize(request_data, token)
}).done(function(data) {
// Process your data here
console.log(data)
});
}
</CODE>
It works fine for a GET request but as soon as I try to do a PATCH request it gives me an error 401 (unauthorised). I think I am doing something wrong with the way I form the request. Do the parameters (i.e. the password field and new password) need to be part of the signature hash or should it be separate?
<CODE>
// Initialize
const oauth = OAuth({
consumer: {
key: 'consumer_key',
secret: 'secret'
},
signature_method: 'HMAC-SHA1',
hash_function(base_string, key) {
return CryptoJS.HmacSHA1(base_string, key).toString(CryptoJS.enc.Base64);
}
});
const request_data = {
url: 'ht tps :// api.smugmug.com / api / v2 / album / xhXXXX',
method: 'PATCH',
data: {Password: "temp123"} // Should this be here??
};
// Note: The token is optional for some requests
const token = {
key: 'key',
secret: 'access_token'
};
function loadDoc() {
console.log(oauth.authorize(request_data, token))
$.ajax({
url: request_data.url,
type: request_data.method,
headers: {
Accept : "application/json",
'Content-Type' : 'application/json'
},
data: oauth.authorize(request_data, token)
}).done(function(data) {
// Process your data here
console.log(data)
});
}
</CODE>
Tagged:
0
Comments
Hi,
Me too, doing an Android app, Having the POST/GET working with Oauth.
PATCH keeps sending me back "Unable to respond to any of these challenges: {none=WWW-Authenticate: None realm="SmugMug"}".
It's like Im not even sending any Authorization at all...
Anyone? Thanks a lot.