BookmarkSubscribeRSS Feed
CR-Horton
Fluorite | Level 6

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?

5 REPLIES 5
ChrisHemedinger
Community Manager

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.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
CR-Horton
Fluorite | Level 6

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.

CR-Horton
Fluorite | Level 6

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!

Interesting.png

 

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.


CR-Horton
Fluorite | Level 6
Following up on my previous message.

Just curious is there is a way to suppress the array wrapper "[" and "]" within the proc JSON output file.
BillM_SAS
SAS Employee

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: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1523 views
  • 3 likes
  • 3 in conversation