Getting status code 400 Bad Request when making HTTP request to shopify

Highlighted
New Member
3 0 0

I'm trying to retrieve a list of our orders from Shopify inside of Salesforce, and for whatever reason, I can't accomplish this using APEX. When I try to make a simple HTTP request to the Shopify API from the developer console utilizing a class I wrote, I continually get a 400 response that the request is bad. If I copy the generated URL into the console and CURL it, I get a response just fine. The URL I am hitting is authorized in my remote site settings as well. Code below:

Http http= new Http();
HttpRequest request = new HttpRequest();
HttpResponse response;
Blob headerValue;
String authorizationHeader = '';
String url = 'https://myKey:myPW@' + shopify_url + '/admin/api/2020-04/orders.json' + '?updated_at_min=' + system.now().addminutes(-60) + '&updated_at_max=' + system.now() + '&status=any&limit=250'; request.setEndpoint(url);
request.setMethod('GET');
request.setHeader('Content-Type', 'application/json');
//headerValue = Blob.valueOf(shopify_key + ':' + shopify_password); //authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue); //request.setHeader('Authorization', authorizationHeader); request.setTimeout(60000); // if running test json is set from test case response = http.send(request);


The response I get, for whatever reason, contains no meaningful error message.  I'm not sure if this is because Shopify is not returning one, or Salesforce is discarding it, or something else is going on.  Regardless, it makes no sense to me.


As you can see, I was initially trying to set an authorization header, which did not work, so I tried a more direct method of just dropping the key/pw into the UR (as suggested by the Shopify API) to no avail.

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1041 140 167

Hey @AdMagic 

 

Try setting the header like this:

 

request.setHeader('X-Shopify-Access-Token', '...password...');

Have you tried without the url params?

 

If you're still stuck please provide a request ID from the response headers.

Notice; Out of office, replies will be delayed until my return. Thanks!
0 Likes
New Member
3 0 0

@SBD_ is the right header X-Request-Id?  If so, when i log it, the request ID is null.

0 Likes
Highlighted
New Member
3 0 0

@SBD_ Actually, I ran again and something must have been off (may have had the key entered not-case sensitive).

 

Here's the last request I sent:  47bae4fb-85b1-4563-8c8a-667d1860589a

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1041 140 167

Hey @AdMagic 

 

Looks like the uri is: admin/2020-04/orders.json, it should be: admin/api/2020-04/orders.json

 

Notice; Out of office, replies will be delayed until my return. Thanks!
0 Likes