title: "(403) Forbidden" when trying to send an image to my custom AutoML model via the REST API
body: <p>I am having issues with implementing a custom AutoML model in a .NET web app that allows sending images via the REST API to be recognized. I keep getting errors.</p>
  
  <blockquote>
    <p>The remote server returned an error: (403) Forbidden.</p>
  </blockquote>
  
  <p>I have an image and converted it into a string of bytes called <code>imageBytesString</code> and have created the jsonRequest object like this:</p>
  
  <pre><code>string jsonRequest = "{\"payload\":{\"image\":{\"imageBytes\":\"" + imageBytesString + "\"},}}";`
  </code></pre>
  
  <p>Then I'm doing a POST request like follows:</p>
  
  <pre><code>WebRequest request = WebRequest.Create(@"https://automl.googleapis.com/v1beta1/projects/PROJECT_ID/locations/us-central1/models/MODEL_ID:predict");
  request.Method = "POST";
  request.ContentType = "application/json";
  request.Headers.Add("Authorization", "Bearer GCLOUD_ACCESS_TOKEN");
  
  using (var streamWriter = new StreamWriter(request.GetRequestStream()))
  {
      streamWriter.Write(jsonRequest);
  }
  </code></pre>
  
  <p>Then when it hits <code>request.GetResponse();</code> if gives me the above error with no other information.</p>
  
  <p>For reference, these are the snippets taken from the bottom of the PREDICT page on my custom AutoML model:</p>
  
  <p><strong>request.json:</strong></p>
  
  <pre><code>{
    "payload": {
      "image": {
        "imageBytes": "YOUR_IMAGE_BYTE"
      },
    }
  }
  </code></pre>
  
  <p><strong>Execute the request:</strong></p>
  
  <pre><code>curl -X POST -H "Content-Type: application/json" \
    -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
    https://automl.googleapis.com/v1beta1/projects/PROJECT_ID/locations/us-central1/models/MODEL_ID:predict -d @request.json
  </code></pre>
  
  <p>Thanks</p>