Unsolved url_metrics - Error deserializing POST body
-
Hi,
I'm trying to reproduce this Postman url_metrics request in Google Apps Script (GAS) :
But in GAS, I get this error :
I suspect it's the body (line 90) that causes the issue, but can't figure out how to fix it.
Any suggestion ?
-
Hello, try to use this way it will work:
$username='Access ID'; $password='Secret Key'; $URL='https://lsapi.seomoz.com/v2/url_metrics'; $payload = json_encode(array("targets" => ["moz.com"])); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$URL); curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); $result=curl_exec ($ch); $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code curl_close ($ch); print_r(json_decode($result, true));
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
Unsolved Generate an Access ID and API key
Hello, I can't generate an Access ID and API key for my account.
API | | OlegShavilov
I need a Links API and I'm ready to buy a paid subscription, but I can't do it. Link https://moz.com/products/mozscape/access
Redirected to https://moz.com/api/dashboard And i dont see any options for create Access ID0 -
Unsolved "The account does not have access to that quota" - API v1 URL Metrics
Hi! On one of our servers we get the message "The account does not have access to that quota" when pulling data for v1 URL Metrics endpoint in the API.
API | | aheitzman
This only happens on one specific server, others have worked flawlessly. Any idea of what might be going on? Thanks0 -
Unsolved Api limits on free plan
Good afternoon. I tried connecting free access to api https://moz.com/help/links-api/v1-archive/v1-free-api-access to retrieve DA data. After several requests to the api I got a message: "Your monthly row limit reached" Can you tell me what this error is related to? Or Moz doesn't have free api access anymore?
API | | Dima124dsfg1 -
API url_metrics Error deserializing POST body
Getting error in https://lsapi.seomoz.com/v2/url_metrics API I'm using Basic Auth for authentication. { "name": "Bad Request", "message": "Error deserializing POST body"} CVW2T4f
API | | verdet32321 -
Crawl error HELP!
Hi. I have two campaigns that are constantly giving crawl errors, but in Search Console I don't. How can I do to fix this? The URLs are: https://www.starmeup.com/blog/en/ and https://www.starmeup.com/blog/es/ Thanks
API | | lala20172 -
Error when generating secret API key
Hi, I am trying to generate an API key for the past 24 hours and I keep on getting the same vague explanation (attached below) of the error. Help Hub had no responses regarding the error also. "Oops - Something went wrong while trying to get your API Credentials. Please try again or check out the Help Hub if you are still experiencing issues." Appreciate any assistance on solving this issue. Thanks! Ian
API | | kwaken0 -
Moz crawl error? DA & Linking domains significant drop.
Hi guys! Our site www.carwow.co.uk appears to have been punched in the face by the latest Moz update. It's claiming our #linking root domains has dropped from 225 to 135 and has subsequently hit our DA from 38 to 35. We haven't disavowed any links and our off-site strategy has been going well the past 2 months. Search performance has increased by around 15% (around 5k sessions) and rankings have improved week on week. Any idea if this is a Moz error? That's almost a 50% drop in linking root domains. Thanks, James
API | | Matt.Carwow0