CPIGroup / phpAmazonMWS

A library to connect to Amazon's MWS web services in an object oriented manner
Apache License 2.0
257 stars 229 forks source link

Many Problems with Feed Submission #100

Closed gsobero closed 7 years ago

gsobero commented 8 years ago

Hello,

I am trying to use the amazon feed class to upload a single line of inventory. I know the feed works because I have submitted it through their interface and it works just fine.

I keep running into two issues that I cannot for the life of me solve.

The first issue is that I keep getting an error about the keys. The response says "Keys cannot contain" and then it has a "Tab" character. There is indeed tabs in my feed as it is a text tab delimited file. I was wondering why the tab would still be showing up, and it's showing because even though the content gets encoded into MD5, the code still puts the original content in the POST parameter. I don't know how or why to fix the issue. I tried to circumvent it by just excluding the post parameter, by making the following change.

$response = $this->sendRequest("$url?$query",array('Header'=>$headers));//,'Post'=>$this->feedContent));

I just commented out that second part. That got me through that error, but then I run into a second error.

It keeps telling me the signature calculated doesn't match the signature sent. I wasn't sure if there was something wrong with the signature creation, so I actually took the methods and calculations from a different API call that I had that was working, and pasted them into your code. There were only a few differences in how it calculated the signature, but even with this code, which I know works and tested several times before and after, I get the same error. I am at my wits end, I just can't figure out what's wrong with the signature. Can anyone help?

below is my code, its essentially the same as the sample. I filled out the configuration page correctly, it's the exact same values as the other API call I have that works. Though that one uses a completely different architecture, it does not have a good simple feed submission function like this one. I really hope I can get this to work.

$amz=new AmazonFeed(); //if there is only one store in config, it can be omitted
$amz->setFeedType('_POST_FLAT_FILE_INVLOADER_DATA_'); //feed types listed in documentation
$amz->setFeedContent($feed); //can be either XML or CSV data; a file upload method is available as well
$amz->submitFeed(); //this is what actually sends the request

$response =  $amz->getResponse();

I would appreciate any advise on the issue, thank you.

saikaze commented 8 years ago

First of all, if you have multiple stores in your config file, you need to specify store name while creating AmazonFeed. Then, be sure that your $feed var contains valid string. If you are not sure, try to load content from file. Try something like this:

    $amz = new AmazonFeed("myStore"); 
    $amz->setFeedType("_POST_FLAT_FILE_LISTINGS_DATA_"); 
    $filename = public_path() . '/' . $file; // your file url
    $amz->loadFeedFile($filename);
    $amz->submitFeed();
    $response = $amz->getResponse();
Peardian commented 8 years ago

That sounds odd. Unfortunately, I mainly have experience with XML feeds, so I do not know the cause of the error message off-hand. What is the error code for the message? Knowing that code might help us look for answers.

I can already say that disabling the post body is not the way to solve the problem, because that is where the actual feed contents are sent. The contents are only converted to MD5 for the sake of creating a header, as Amazon cannot decode the MD5 hash. Since the signature is generated from the feed contents, changing the contents (by omitting it) will cause Amazon's generated signature to be different from yours, which is where the signature error comes from.

Normally, I would say that something like this would be outside the scope of this library, but the fact that you were able to upload the same feed on Amazon's site directly means the library could be doing something different.

I am not able to look into it myself at this time, so searching with the error code number might get some better answers in the meantime.

gsobero commented 8 years ago

Thank you both for the quick response.

saikaze: I only have the one store, but I will try loading the file tonight and let you know what happens. Do you really think that has something to do with the signature?

Peardian: I am away from that workstation so I don't recall the error code but I do remember it saying it meant the signature didn't match. Yes, I eventually used rawurlencode to put the post back into the code, and that did get me past that part but again I was stuck on signature not matching. I checked the usual issues, it's definitely using the right secret key, and I see that it's putting the parameters in alphabetical order before generating the signature. The only other thing I can think to do is log the params one by one and see if they are all being included and if they are indeed in alphabetical order.

Peardian commented 8 years ago

Don't worry about the signature mismatch, that likely isn't the problem. The mismatch came from disabling the post body.

You could also try using getOptions to see if any of the parameters or their keys have a tab in them for some reason.

gsobero commented 8 years ago

The mismatch was happening even after I re-enabled the post body using rawurlencode on the feedcontent. At first it thought maybe it was because it just wouldn't take tab delimited files through the API, so tried changing it into a csv. However when I do that, it then gives me the error "Keys cannot contain ," . I'm curious, at this point, might it be easier to figure out how to write an XML for it than to keep pounding away at making a flat file work. Has anyone ever successfully used a flat file upload with this system?

Peardian commented 8 years ago

Learning to write XML might possibly solve your problem, but it would not help catch any bugs in flat files if there is one. I don't know for sure whether or not anybody has done flat files before, but I haven't had any bug reports about it before, either.

I recommend trying a dump of getOptions, just in case the parameter keys are somehow getting messed up. You don't have to show me the output or anything, just let me know if all of the keys are tab-free.

If the options are all tab-free, then the only problem is the structure of the feed itself. In that case, you'd have to ask Amazon MWS support about it.

gsobero commented 8 years ago

Thanx, I will try both loading a file like saikaze said and dumping getOptions. I can probably show them here, though it won't be until tonight.

gsobero commented 8 years ago

OK, I used a file and still got the signature error below:

[Urgent][2016/09/07 18:46:14 guest@24.120.104.234 AmazonFeed.php:263 checkResponse] Bad Response! 403 Forbidden: SignatureDoesNotMatch - The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

And here I iterated through the options array and printed them.

SellerId => AblablablaT AWSAccessKeyId => AblablablaQ SignatureVersion => 2 SignatureMethod => HmacSHA256 Version => 2009-01-01 Action => SubmitFeed FeedType => _POST_FLAT_FILE_INVLOADERDATA

I'm going to work on a different part but I'll back later tonight to give it another shot. If I can't get it to work, does someone know where I could get a good template?

Peardian commented 8 years ago

Make sure you undo any of the code changes you did previously. Your original message makes it sound like you didn't start getting the signature mismatch error until after you started changing things in the code.

Also, I feel I should clarify, in terms of the progress from sending the message to Amazon and Amazon processing it, the "keys" error is farther along the process than the signature mismatch error. So, the change in error responses was actually a step backward rather than a step forward.

gsobero commented 8 years ago

Yes, I reverted all changes back to what they were, that last attempt was with no changes in the code.

Yes it's true, at first I was getting the "keys" error. I then changed the code to try to circumvent it but I changed that back to how it was a while ago. As of right now I'm back to the original code, only difference is now I'm loading the file instead of a string, and getting the signature error.

Are you saying that I should go back to loading the string when I was getting the "keys" error, and try to solve for that since it's farther along?

saikaze commented 8 years ago

I've checked few things for you, and I can say, that Amazon could throw HTTP 403 (about wrong signature) just because can't understand your request. You can reproduce and confirm that error easy, just by comment feed content as you said at the beginning:

$response = $this->sendRequest("$url?$query",array('Header'=>$headers,'Post'=>$this->feedContent)); // That will work

$response = $this->sendRequest("$url?$query",array('Header'=>$headers)); // That won't

Because Amazon expects both, Header and Post, request has to contain them, if not, Amazon should throw missing Post error, but returning wrong signature error. I've checked it and can confirm that happened to me when I delete Post var from request, as you at the beggining.

Try to make clean installation, as I do, and everything should work. Just do no more than here: https://gist.github.com/saikaze/7dc4725a277c75461089081666b5c97f

After you do that, you will be sure that communication with Amazon is ok, and you can start to trying send valid feed content.

Peardian commented 8 years ago

Uploading the feed from a string should work exactly the same way as loading from a file if the string's contents match the file contents perfectly. Are you using file_get_contents to make your string? If not, I would check to see if using it gives the same result as loading the file, or if it gives the same result as the string you were using before.

gsobero commented 8 years ago

saikaze: I will give it another try with a clean install, but it won't be for another week, I won't be back in that office until the 19th.

Peardian: I will give that a try too. I'll post my results when I get back there.

Peardian commented 7 years ago

@gsobero Have you had any luck with getting the feeds to work?

gsobero commented 7 years ago

@Peardian Unfortunately no, we have limited time so I have moved to a completely different part of our project and will come back to this maybe next month. I hate to leave the issue hanging but I had to move on for the time being, I will come back to it though.

Peardian commented 7 years ago

I completely understand. I will leave this open for a now, but I may have to close it if too much time passes unless someone else has the same problem.

Peardian commented 7 years ago

It has been quite a while now, so I'm going to close this now.

developer-gurpreet commented 5 years ago

Hi I have same issue, how you solved this?

Peardian commented 5 years ago

A definite solution for this problem was not found, as indicated by the last few comments. I can reopen this issue if the advice here does not solve the problem.