inventory_level/set.json html response

hitRo
New Member
1 0 0

HI, guys, 

first, i am up to date with other posts regarding cookies in the session.

i work with an app which at some point throws a JS in place. i did a lot of integrations in this manner.

i even manage to create products in shopify, update products, update variants with no problem.

but now i am trying for a lot of time to set the inventory level using ES5 (i think is 5).

the request works on SoapUI (not key:pass@hostname but with the header Authorization: Basic base64 thingy)

what doesn`t work is the basic AJAX request below:

(feel free to use the code if you want. it usually works )

as you can see, i tried a lot of headers (all the combinations you see below).

as a response, i get the <html><body><noscript><a href="https://accounts.shopify.com/oauth/authorize?client_id=...>continue</a> and a redirect to the same url (i think is the login/authentication page).

 

 

 

 

var myData = JSON.parse('{"location_id": 643080889,"inventory_item_id": 43501817,"available": 30}');
var parms = {};

parms.url 		= 'https://myapikey:myapipass@myplatform.myshopify.com/admin/api/2022-01/inventory_levels/set.json';
parms.async 	= false;
parms.method 	= 'POST';
parms.data 	= JSON.stringify(myData);

var myVariant = shopify_sendDataToShopify(parms);

function shopify_sendDataToShopify(objData){
	var data;
	var dm = new shopify_ajaxCall(objData);
	dm.onSuccess = function(reply) {
				var data = reply;
			};
	dm.onError = function(err){	}
	dm.execute();
	return data;
}

function shopify_ajaxCall(objParms) {
	this.onSuccess = function(){};
	this.onNoReply = function(){};
	this.onError= function(){};
	this.request= null;
	this.url=objParms.url;
	var me= this;
	this.execute =
		function() {
			this.url = objParms.url;
			this.request = new ActiveXObject("MSXML2.XMLHTTP");
			this.request.open(objParms.method, objParms.url, objParms.async);
			//this.request.setRequestHeader("Authorization","Basic YzE4MDU0NWM4Y2FlODZsomefMDljMWYxYWI2YjODQ3YTM2NWVkOWY=");
			//this.request.setRequestHeader("Accept-Encoding","gzip,deflate");
			//this.request.setRequestHeader("Content-type", "application/json");
			//this.request.setRequestHeader("User-Agent","Apache-HttpClient/4.5.5 (Java/12.0.1)");
			this.request.setRequestHeader("X-Shopify-Access-Token","shppa_...");
			this.request.onreadystatechange=
				function() {
					if (me.request.readyState==4) {
						if (me.request.status==200){
							me.onSuccess(me.request.responseText);
							
						}
						else{
							me.onNoReply();
						}
					}
				}
			try {
				this.request.send(objParms.data);
			}
			catch(e) {
				this.onError(e);
			}
		}
}

 

 

 

 

 

 

Replies 0 (0)