Solved

Shopify Bulk Operations Issue

aryancampervan
New Member
4 0 0

I'm having an issue downloading my query results from a bulk mutation url:

https://shopify.dev/tutorials/perform-bulk-operations-with-admin-api#download-result-data

I can download the data when I access it from my browser, but when I try to do so from my private app I get the following error:

AccessDenied: Anonymous caller does not have storage.objects.get access to the Google Cloud Storage object.

I tried passing my access token when I made the GET request, but that still made no difference. Please lmk if you've encountered this and how you got around it!

 

Some more info:

I am using Rust, and simply running a cURL command from it. I used the same technique to run and poll the bulk query in the first place, and those worked fine; the url used in the function below is extracted from the polled result.

 

 

/// Gets query results from url and deserializes into struct                                     
pub fn get_query_results(data: PolledResult, query_name: Option<&str>) -> Result<()> {           
    let url = data.url.unwrap(); --> String                                                      
    let token = env::var("NTP_TOKEN")?;                                                
                                                                                                 
    // Send GET resuest using curl                                                               
    let res = Command::new("sh")                                                  
        .arg("-c") --> &mut Command                                                              
        .arg(format!(                                                                            
            "curl -X GET {} \                                                                    
                -H 'X-Shopify-Access-Token: {}'                                                  
                ",                                                                               
            url, token,                                                                          
        ))                                                                                       
        .output()                                                            
        .expect("cURL process failed to execute!");      
                                                                            
    // Get response string and clean it up                                                       
    let res = String::from_utf8_lossy(&res.stdout).to_string();                                  
    let res = res.replacen("\\", "", res.len());                                
                                                                                 
    // DEBUG                                                                                     
    println!("Query Results: {:?}", res);                                                        
                                                                                                 
    Ok(())                                                                                       
}                                                                                                

 

Accepted Solution (1)

kpublik
Visitor
2 1 0

This is an accepted solution.


@aryancampervan wrote:

I tried passing my access token when I made the GET request, but that still made no difference. Please lmk if you've encountered this and how you got around it!

 

I had the same problem.  I could run a Bulk Operation query in the GraphiQL web application and download the data via the results URL.  However, when I used a different HTTP client (Paw for Mac), the result URL wouldn't work when copied to my browser; I received the access denied error.

What I found was that my HTTP client application was not escaping the Unicode characters in the JSON formatted results URL.  So, all the ampersands (&) in the query string portion of the results URL were coded as \u0026, and forward slashes were showing as http:\/\/storage.googleapis.comxxxxxx.  While the slashes were easy to spot, the converted ampersands were not immediately visible to me in the very long URL produced by the API.

To correct this, all I had to do was update one of my JSON formatting preferences in Paw so that the results URL was formatted correctly.

Though not a Rust programmer (I use Go), I suspect your problem is similar and can be corrected via some feature of Rust.

I hope this helps.

 

 

View solution in original post

Replies 4 (4)

HunkyBill
Shopify Expert
4846 60 552

Not too sure you'll run into Rust coders in this community, but I am sure you'll figure out your problem soon enough. You know it is simple in the end. Given a working URL, download the file stored there. Good luck!

 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com

kpublik
Visitor
2 1 0

This is an accepted solution.


@aryancampervan wrote:

I tried passing my access token when I made the GET request, but that still made no difference. Please lmk if you've encountered this and how you got around it!

 

I had the same problem.  I could run a Bulk Operation query in the GraphiQL web application and download the data via the results URL.  However, when I used a different HTTP client (Paw for Mac), the result URL wouldn't work when copied to my browser; I received the access denied error.

What I found was that my HTTP client application was not escaping the Unicode characters in the JSON formatted results URL.  So, all the ampersands (&) in the query string portion of the results URL were coded as \u0026, and forward slashes were showing as http:\/\/storage.googleapis.comxxxxxx.  While the slashes were easy to spot, the converted ampersands were not immediately visible to me in the very long URL produced by the API.

To correct this, all I had to do was update one of my JSON formatting preferences in Paw so that the results URL was formatted correctly.

Though not a Rust programmer (I use Go), I suspect your problem is similar and can be corrected via some feature of Rust.

I hope this helps.

 

 

HunkyBill
Shopify Expert
4846 60 552

That is a good point! Early on I learned that when you paste the URL provided by Shopify into a browser, of course the browser auto-corrects the URL and uses it fine. My HTTP client also has no trouble handling the URL. But when you eyeball it, it can indeed seem loaded with extra characters as everything appears escaped. Good eye!

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
aryancampervan
New Member
4 0 0
That was exactly the issue I was having. Thanks!