REST API: Creating binary workspace items

REST API: Creating binary workspace items

Anonymous
Not applicable
1,198 Views
5 Replies
Message 1 of 6

REST API: Creating binary workspace items

Anonymous
Not applicable

I am trying to figure out how to add images to an item I'm creating via the API from VBA (in SolidWorks).  I'm using this blog post (specifically, the approach using WinHttp.WinHttpRequest.5.1) to understand how to post a binary file to an API with VBA; however, there seems to be several things that need to be changed to get this approach to work with PLM 360, and I'm not sure what they all are.

 

Here are the main things that are puzzling me at the moment:

  1. The PLM 360 documentation seems to indicate that one request is being sent in two parts, but I don't understand how to do that in VBA.
  2. The code in the blog post surrounds the binary file with boundaries.  Is that necessary?
  3. The code in the blog post includes the Content-Disposition and a few other things in the binary portion.  Is this necessary for PLM 3660?
  4. The caveat to the pvToByteArray function is confusing to me.  I understand that it is converting back to a byte array the string containing the file data, but if #3 above is not necessary in PLM 360, is it necessary to convert the file to a string and then back to a binary blob, or does that result in it being possible to pass baBuffer without failure?
  5. How do I include the rest of the information in the request for creating the item?  I suppose this is somewhat related to #1 above.

 

 

To say the least, I really have no idea what I'm doing here, and I'm not sure if this is the right place to ask these questions or if it would be better to ask them of some place more familiar with SolidWorks' VBA, but I would greatly appreciate any help anyone can provide.

0 Likes
1,199 Views
5 Replies
Replies (5)
Message 2 of 6

gasevsm
Alumni
Alumni
Hi Tim,
Yes it's multipart payload first part is metadata, second is binary. I'll post tonight a C# project depicting the file upload syntax. Try using it to translate into VBA code. Hopefully you wouldn't mind sharing with the community once make it happen? Cheers,

Martin Gasevski | Fusion 360 Team Product Manager
0 Likes
Message 3 of 6

Anonymous
Not applicable

Thanks!  And yes, I'll definitely be sharing when I get this finished.

0 Likes
Message 4 of 6

gasevsm
Alumni
Alumni

Here it is. Hope you get it working. Let me know if have further questions or comments on this topic,


Martin Gasevski | Fusion 360 Team Product Manager
0 Likes
Message 5 of 6

Anonymous
Not applicable

I'm a mechanical engineer who knows how to do some programming on the side, so I've never done any C# programming, have done very little work with REST APIs (my work with PLM 360 encompasses 99.9% of that), and have never uploaded a file via an API before.  I've done a good bit with VBA and Matlab, and a little with JavaScript/HTML/CSS, but to say the least, I feel a little lost trying to decypher what's going on in the program you sent.  To be clear, I do eventually want to make my SW macros upload attachments associated with the items it's adding, but at this point, I just want to be able to include an image of the item on the item details page.  As far as I can tell, the C# program you sent doesn't do that.  That would be fine if I could figure out what was important to keep and what wasn't, but I haven't been able to so far.

 

All that to say, I'm perfectly willing to put as much effort as is necessary to figure things out on my own, but I don't really know what I'm looking at here or how to translate it to what I need to do.  I think StackOverflow may be a better place for me to ask this question since they would have people with experience in both VBA and REST APIs that would possibly be better able to explain some of these concepts to me.

 

0 Likes
Message 6 of 6

gasevsm
Alumni
Alumni

you are coreect - the sample projects adds a file to attachments tab and is using this endpoint. http://help.autodesk.com/view/PLM/ENU/?guid=GUID-F31EF246-A5EA-4892-B188-AA3F11DE4DBB

 

what you need is replace it with this endpoint, which has equal payload requirements. http://help.autodesk.com/view/PLM/ENU/?guid=GUID-D189F997-B297-4C83-A249-B4A5F3671E39

 

Let me see if can find a simple VBA sample calling REST that you can use as baseline.


Martin Gasevski | Fusion 360 Team Product Manager
0 Likes