Reputation: 21
I am trying to create a bucket as described in Create an App-Managed Bucket and Upload a File. When I use cURL in a command-box, it works good:
curl
-v "https://developer.api.autodesk.com/oss/v2/buckets"
-X "POST"
-H "Content-Type: application/json"
-H "Authorization: Bearer ObfuscatedBucketCreateToken"
-d "{"""bucketKey""":"""itx5""", """policyKey""":"""transient"""}"
Now I try to do the same with C# / visual studio:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"https://developer.api.autodesk.com/oss/v2/buckets");
request.Method = "POST";
UTF8Encoding encoding = new UTF8Encoding();
Byte[] byteArray = encoding.GetBytes(@"{""bucketKey"":""Itx7"", ""policyKey"":""transient""}");
request.ContentLength = byteArray.Length;
request.ContentType = @"application/json";
request.Headers.Add(@"Authorization: Bearer ObfuscatedBucketCreateToken");
using (Stream dataStream = request.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
}
using (HttpWebResponse webRresponse = (HttpWebResponse)request.GetResponse())
{
long length = webRresponse.ContentLength;
using (Stream stream = webRresponse.GetResponseStream())
{
// do your thing
}
}
On the request.getResponse() I get the exception "The remote server returned an error: (400) Bad Request".
I a similar way, I am able to get OAth-tokens, but somehow, when I try to create a bucket, it always returns this exception.
Why do I get this exception? Is there a way to investigate why I get this exception?
Upvotes: 1
Views: 685
Reputation: 2196
It looks you specified the bucket name with upper case when testing in C#. ""Itx7"" API help says:
HTTP / 1.1 **400** Bad Request
......
{
**"reason":"Valid field 'bucketKey' must be of the form [-_.a-z0-9]
{3,128}"**
}
We have a blog on bucket. Most of the descriptions are still applied to new version:
http://adndevblog.typepad.com/cloud_and_mobile/2015/01/buckets-in-autodesk-view-and-data-api.html
Hope these are helpful.
Regards,
Xiaodong Liang
Forge Adovater
Developer Technical Services
Autodesk
Upvotes: 2