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.
Try setting the header like this:
Have you tried without the url params?
If you're still stuck please provide a request ID from the response headers.