Hi All,
I am trying to test updating a product using a Proc HTTP Put statement, but not having much luck. The code runs fine and I get a successful response, however what I am trying to update is not getting updated. Here is my code:
proc json out="XXXXXXXX\SAS\SAS Output\Test.json";
export XX / nosastags;
run;
filename test 'XXXXXXXX\SAS\SAS Output\SAS Output\test.json';
filename resp 'XXXXXXXX\SAS\SAS Output\SAS Output\resp.txt';
filename head 'XXXXXXXX\SAS\SAS Output\SAS Output\head.txt';
proc http
method="put"
url="https://api.bigcommerce.com/stores/XXXXXXX/v3/catalog/products/114"
ct="application/json"
in=test
out=resp headerout=head;
headers
"Accept"="application/json"
"x-auth-token"="XXXXXXXXXXXXXX";
run;
I have attached the headers (head.txt), response (resp.txt) and the json file I am using in the in statement (test.json) for proc http.
Any idea why it would be running fine but not updating the weight from 50 to 100?
According to the bigcommerce doc and what I see in your code, it seems you're doing the right things.
You might be able to simplify the call by including just the field you want to update (ex: weight) and see if that helps. Perhaps use a tool like Postman to verify that all works as expected before running in SAS.
Thanks, @ChrisHemedinger
I thought the same and did try and limit it to just the weight field and ended up with the same result.
I sent a test request using the tool at the bottom of the page here and it worked successfully. I also verified I have the appropriate permissions. Just strange the response I am getting without anything successfully updating.
Thanks.
Quick update - I was able to get this to work by removing the array wrapper "[" and "]" Is there a way to suppress this in the proc JSON statement?
Thanks!
Updating my proc JSON statement to the following works, but I don't want to have to define each specific value since in many cases I will be dealing with dozens at a time.
proc json out="XXXXX\SAS\SAS Output\Test.json" pretty nosastags;
write open object;
write values "id" "114";
write values "weight" "300";
write close ;
run;
I am hoping for a single statement that will suppress the array so I only have an object.
As you have found, there does not appear to be a way to get the export statement to give you the JSON format you want. While not ideal, one possibility is to write a program to strip off the outer array characters after the JSON file is created.
Another possibility might be to write a program to dynamically create the PROC JSON code that utilizes WRITE statements to produce the desired output. A proof-of-concept of this technique is in this post. I do not know enough about your requirements to be able to say if the dynamically generated PROC JSON code will work in your case.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.