0

I'm getting this error using Amazon Advertising API while trying to create new keywords:

"code":"422"

This is my PHP Code:

curl_setopt($ch, CURLOPT_URL, $std_url . "/v2/sp/keywords"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);


$data_string = array(
    "campaignId" => "111111111111",
    "adGroupId" => "2222222222222",
    "state" => "enabled",
    "keywordText" => "YetAnotherKeyword",
    "matchType" => "broad",
    "bid" => "0.05");

curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);

$headers = array();
$headers[] = "Content-Type:application/json";
$headers[] = ("Authorization: Bearer " . $accesstoken);
$headers[] = ("Amazon-Advertising-API-ClientId: ". $client);
$headers[] = ("Amazon-Advertising-API-Scope: " . $API_Scope);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
echo $result;
henankoko
  • 11
  • 1
  • are those values like `campaignId` and `adGroupId` what you're using or just redacted? – Lawrence Cherone Nov 23 '21 at 21:06
  • you probably should be doing `curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data_string));` though 422 is generally not used for invalid content/media type 415 – Lawrence Cherone Nov 23 '21 at 21:07
  • Those values are redacted. I've already tried json_encode($data_string) but the result is the same. – henankoko Nov 23 '21 at 21:56


  • > 422 Unprocessable Entity (WebDAV; RFC 4918) > The request was well-formed but was unable to be followed due to semantic errors
    – quinny Nov 27 '21 at 22:59

1 Answers1

1

I've got the solution. The array needs to be modified like this:

$data_string = array(array(
    "campaignId" => "111111111111",
    "adGroupId" => "2222222222222",
    "state" => "enabled",
    "keywordText" => "YetAnotherKeyword",
    "matchType" => "broad",
    "bid" => "0.05"));
henankoko
  • 11
  • 1