I'm creating a listing into Etsy using php oAuth.I'm sending following params to api call "quantity,title,description,price,who_made,when_made,is_supply".
I'm following the document as reference here
This is the process flow
Authenticating with etsy using oAuth.
Getting scopes using this api call https://openapi.etsy.com/v2/oauth/scopes
These are working fine.But while creating listing i'm getting following error.
"Invalid auth/bad request (got a 403, expected HTTP/1.1 20X or a redirect)"
3.The process I followed for create listing
$url = "https://openapi.etsy.com/v2/listings/";
$params = array('description' => 'thisisdesc', 'price'=>'1.00', 'quantity'=>'2', 'title'=>'thisistitle', 'who_made'=>'collective', 'is_supply'=>'false','when_made'=>'2010_2015', 'category_id' => '69105467','shipping_template_id' => '110906760173');
$data = $oauth->fetch($url, $params , OAUTH_HTTP_METHOD_POST);
$json = $oauth->getLastResponse();
print_r($json);
It displays error message.Invalid auth/bad request.
Any ideas/suggestions please.
Change
$url = "https://openapi.etsy.com/v2/listings/";
to
$url = "https://openapi.etsy.com/v2/listings";
The extra / at the end may be causing the issue
Can you try removing the '/' and if possible show the response details.
Related
I am trying to integrate google index API with my website in order to index my side but i am getting 401 error.
I searched and got this solution for my problem.
Google Indexing API - 403 'Forbidden Response'
But this is also not working in my case since i have verified that i am owner in google search console plus integrating right JSON authentication file.
I am checking index matrics but and getting all number of calls in my console platform.
require_once 'google-api-php-client/vendor/autoload.php';
$client = new Google_Client();
// service_account_file.json is the private key that you created for your service account.
$client->setAuthConfig('service_account_file.json');
$client->addScope('https://www.googleapis.com/auth/indexing');
// Get a Guzzle HTTP Client
$httpClient = $client->authorize();
$endpoint = 'https://indexing.googleapis.com/v3/urlNotifications:publish';
// Define contents here. The structure of the content is described in the next step.
$content = '{
"url": "http://example.com/jobs/42",
"type": "URL_UPDATED"
}';
$response = $httpClient->post($endpoint, [ 'body' => $content ]);
$status_code = $response->getStatusCode();
any help will be appreciated.
Thank in advance
I'm trying to use the DocuSign PHP SDK to send a signing request based on a template. I am attempting to follow the steps outlined in this example: https://developers.docusign.com/docs/esign-rest-api/how-to/request-signature-template-remote
To authenticate, I am using a JWT. I assembled a header and payload signed with RSA256 private key generated by DocuSign, and the access token I received in response is in this format:
eyJ0eXAiOiJ-----.yyyyyy-----.zzzzzz-----
(Example, actual token is much longer).
When I try to run this code here (putting in the above access token and my DocuSign credentials as the arguments):
private function worker($args)
{
$envelope_args = $args["envelope_args"];
# Create the envelope request object
$envelope_definition = $this->make_envelope($envelope_args);
# Call Envelopes::create API method
# Exceptions will be caught by the calling function
$config = new \DocuSign\eSign\Configuration();
$config->setHost($args['base_path']);
$config->addDefaultHeader('Authorization', 'Bearer ' . $args['ds_access_token']);
$api_client = new \DocuSign\eSign\client\ApiClient($config);
$envelope_api = new \DocuSign\eSign\Api\EnvelopesApi($api_client);
try {
$results = $envelope_api->createEnvelope($args['account_id'], $envelope_definition);
$envelope_id = $results->getEnvelopeId();
}
catch(ApiException $apiException) {
echo $apiException->getMessage();
}
return ['envelope_id' => $envelope_id];
}
Then I end up catching an exception:
Error while requesting server, received a non successful HTTP code [302] with response Body:
Digging a little deeper and var_dumping the response, the body is indeed empty and here are the response headers:
array(
0 => string 'HTTP/1.1 302 Found'
'Cache-Control' => string 'no-cache'
'Content-length' => string '0'
'Location' => string 'https://account-d.docusign.com/v2.1/accounts/6d7dc630-xxxx-xxxx-xxxx-xxxxxxxxxxxx/envelopes'
'Connection' => string 'close'
)
I have blocked out the the number in the Location section of the response in case it's anything sensitive. Being new to the DS API, I am unclear what this number is. It's not anything I have defined in my configuration for the project.
Does anyone have any idea what this error message indicates? Am I trying to access an incorrect API endpoint? Does this indicate my JWT access token is invalid? Something else?
Thanks for any help you can provide.
A better technique is to use the php quickstart and then copy the example that creates an envelope from a template
Re your current code: I'd check your base path.
Also check your access token. Your software is being redirected to the account server
I am new to yii framework
I tried web service response using curl post but I receive error code on response
$curl = new curl\Curl();
$response = $curl->setOption(
CURLOPT_POSTFIELDS,
http_build_query(array(
'email' => 'sfdsdfsdf',
'access_token' => 'fdsdsfsdfsdf',
'auth_type' => 'fdsfsfsdfsd'
)
))
->post('http://example.com/login/');
var_dump($curl->responseCode); - 404
I tried above code.
That URL http://example.com/login/ does not exist, and correctly responds with a HTTP 404 error: Page Not Found. (also see: List of HTTP Status Codes)
It seems your code is functioning. You may want to change the example.com url to your actual endpoint.
I'm trying to access Magento's REST API in PHP, using Oauth and GuzzleHttp.
I'm basing my example off of this Twitter example:
https://github.com/guzzle/oauth-subscriber
My code so far is:
use GuzzleHttp\Subscriber\Oauth\Oauth1;
use GuzzleHttp\Client;
$client = new Client(array(
'base_url' => 'http://magento',
'defaults' => array('auth' => 'oauth')
));
$oauth = new Oauth1(array(
'consumer_key' => 'magento_key',
'consumer_secret' => 'magento_secret'
));
$client->getEmitter()->attach($oauth);
$response = $client->post('/oauth/initiate');
print_r($response);die();
My host is http://magento. I'm trying to POST my key and secret to /oauth/initiate like is says in the Magento docs.
http://www.magentocommerce.com/api/rest/authentication/oauth_authentication.html#OAuthAuthentication-AuthenticationEndpoints
Does anyone have any insight on what I might be doing wrong? I'm getting a 500 error using Firefox's RESTClient to make this call.
EDIT:
I'm now getting this exception thrown
{
"response": "Client error response [url] http://magento/oauth/initiate [status code] 400 [reason phrase] Bad Request"
}
It's getting a 400 from http://magento/oauth/initiate but this is only when using GuzzleHttp and Oauth. If I make the POST directly within RESTClient as http://magento/oauth/initiate, I get an error response from Magento itself (so it does not 400), and if I add all the necessary params I get the appropriate token responses.
UPDATE:
After inspecting the exception being thrown I'm seeing my authorization array does not conain my callback url. This is suppose to be http://magento/oauth/authorize which I've adde in the RESTClient and it works with the token response. Iv'e tried adding this in my $oauth array as 'callback' and 'oauth_callback' but neither seem to work. I can see this appears in the exception, under my data array, but not in the [authorize] array which I believe it needs to be. I tihnk that's what's missing, if someone has an idea of where it needs to be placed.
I'm trying to get the list of all my friends from the Google plus via API. The user on whose behalf I'm doing this operation previously authorized my request and I got the auth token. I've tried the following code in php:
function CallAPI() {
$opts = array(
"http" => array(
"method" => "GET"
)
);
$url = 'https://www.googleapis.com/plus/v1/people/me/people/visible?key=XXXX';
$context = stream_context_create($opts);
$response = file_get_contents($url, false, $context);
var_dump($response);
}
but I keep receiving HTTP request failed! HTTP/1.0 401 Unauthorized. How can I prove that the user authorized my operations or what am I doing wrong?
Any help is much appreciated.
You need to authenticate the user to use the special keyword "me" so using your simple API key will not work (assuming the key passed is your simple key). Instead, you need to get an access token and pass that.
For a great example of how to do this in PHP using the PHP client library, try the quickstart:
https://developers.google.com/+/quickstart/php
If you are already getting an access token, you can call tokeninfo passing access token to get more information about who the user is associated with it:
https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=ya29.xxxxxxxx...
At this point, you could call:
'https://www.googleapis.com/plus/v1/people/[useridfromaccesstoken]/people/visible?key=XXXX';
To verify that your API key is correct but I would recommend using the client library as demonstrated in the quickstart sample.