868 votes
0 answers
api - How to get product ID of recent created product in PHP from ShopifyClientsRestResponse Object?
I'm creating(adding) Shopify product using Rest API call, Product is created successfully. I need to get Product ID from Shopify response. Here is my function code for creating product:
function store_data($client) // create products
{
$res = $client->post(
"products",
[
"product" => [
"title" => "zarri test",
"variants" => [
[
"price" => "10"
]
]
]
]
);
print_r($res);
}
This create product with no errors. When I print it's response it gives:
Array ( [product] => Array ( [title] => zarri test [variants] => Array ( [0] => Array ( [price] => 10 ) ) ) )
Shopify\Clients\RestResponse Object
(
[reasonPhrase:GuzzleHttp\Psr7\Response:private] => Created
[statusCode:GuzzleHttp\Psr7\Response:private] => 201
[headers:GuzzleHttp\Psr7\Response:private] => Array
(
[Date] => Array
(
[0] => Thu, 20 Oct 2022 15:48:50 GMT
)
[Content-Type] => Array
(
[0] => application/json; charset=utf-8
)
[Transfer-Encoding] => Array
(
[0] => chunked
)
[Connection] => Array
(
[0] => keep-alive
)
[X-Sorting-Hat-PodId] => Array
(
[0] => 135
)
[X-Sorting-Hat-ShopId] => Array
(
[0] => 59545157768
)
[Referrer-Policy] => Array
(
[0] => origin-when-cross-origin
)
[X-Frame-Options] => Array
(
[0] => DENY
)
[X-ShopId] => Array
(
[0] => 59545157768
)
[X-ShardId] => Array
(
[0] => 135
)
[X-Stats-UserId] => Array
(
[0] =>
)
[X-Stats-ApiClientId] => Array
(
[0] => 11741331457
)
[X-Stats-ApiPermissionId] => Array
(
[0] => 375236001928
)
[X-Shopify-API-Terms] => Array
(
[0] => By accessing or using the Shopify API you agree to the Shopify API License and Terms of Use at https://www.shopify.com/legal/api-terms
)
[X-Shopify-API-Version] => Array
(
[0] => 2022-01
)
[X-Shopify-API-Version-Warning] => Array
(
[0] => https://shopify.dev/concepts/about-apis/versioning
)
[HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT] => Array
(
[0] => 1/40
)
[X-Shopify-Shop-Api-Call-Limit] => Array
(
[0] => 1/40
)
[Location] => Array
(
[0] => https://tradeline-5481.myshopify.com/admin/products/7119217361032
)
[Strict-Transport-Security] => Array
(
[0] => max-age=7889238
)
[X-Shopify-Stage] => Array
(
[0] => production
)
[Content-Security-Policy] => Array
(
[0] => default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://*; block-all-mixed-content; child-src 'self' https://* shopify-pos://*; connect-src 'self' wss://* https://*; frame-ancestors 'none'; img-src 'self' data: blob: https:; script-src https://cdn.shopify.com https://cdn.shopifycdn.net https://checkout.shopifycs.com https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://js.braintreegateway.com https://c.paypal.com https://maps.googleapis.com https://www.google-analytics.com https://v.shopify.com 'self' 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fproducts&source%5Bsection%5D=admin_api&source%5Buuid%5D=793e5e3f-94c2-477d-a4ce-b8bd7510cfd3
)
[X-Content-Type-Options] => Array
(
[0] => nosniff
)
[X-Download-Options] => Array
(
[0] => noopen
)
[X-Permitted-Cross-Domain-Policies] => Array
(
[0] => none
)
[X-XSS-Protection] => Array
(
[0] => 1; mode=block; report=/xss-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fproducts&source%5Bsection%5D=admin_api&source%5Buuid%5D=793e5e3f-94c2-477d-a4ce-b8bd7510cfd3
)
[X-Dc] => Array
(
[0] => gcp-asia-south1,gcp-us-east1,gcp-us-east1
)
[X-Request-ID] => Array
(
[0] => 793e5e3f-94c2-477d-a4ce-b8bd7510cfd3
)
[CF-Cache-Status] => Array
(
[0] => DYNAMIC
)
[Report-To] => Array
(
[0] => {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=uygdkKoty3uXdLAgirAOn6BBdYSZOZggrPlxbyjdxF4K5OSTm7hOq2CHvkWNwRmyJ1dUKmBi8SdT5qZ6Ha%2BXdkG3n6aCwsFRj9esKDXqFRs8I91jxZRbPDo5sidcXq0irAhyOnd6nEE2YDL3abM%3D"}],"group":"cf-nel","max_age":604800}
)
[NEL] => Array
(
[0] => {"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}
)
[Server] => Array
(
[0] => cloudflare
)
[CF-RAY] => Array
(
[0] => 75d2e661ccffd1d8-MCT
)
[alt-svc] => Array
(
[0] => h3=":443"; ma=86400, h3-29=":443"; ma=86400
)
)
[headerNames:GuzzleHttp\Psr7\Response:private] => Array
(
[date] => Date
[content-type] => Content-Type
[transfer-encoding] => Transfer-Encoding
[connection] => Connection
[x-sorting-hat-podid] => X-Sorting-Hat-PodId
[x-sorting-hat-shopid] => X-Sorting-Hat-ShopId
[referrer-policy] => Referrer-Policy
[x-frame-options] => X-Frame-Options
[x-shopid] => X-ShopId
[x-shardid] => X-ShardId
[x-stats-userid] => X-Stats-UserId
[x-stats-apiclientid] => X-Stats-ApiClientId
[x-stats-apipermissionid] => X-Stats-ApiPermissionId
[x-shopify-api-terms] => X-Shopify-API-Terms
[x-shopify-api-version] => X-Shopify-API-Version
[x-shopify-api-version-warning] => X-Shopify-API-Version-Warning
[http_x_shopify_shop_api_call_limit] => HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT
[x-shopify-shop-api-call-limit] => X-Shopify-Shop-Api-Call-Limit
[location] => Location
[strict-transport-security] => Strict-Transport-Security
[x-shopify-stage] => X-Shopify-Stage
[content-security-policy] => Content-Security-Policy
[x-content-type-options] => X-Content-Type-Options
[x-download-options] => X-Download-Options
[x-permitted-cross-domain-policies] => X-Permitted-Cross-Domain-Policies
[x-xss-protection] => X-XSS-Protection
[x-dc] => X-Dc
[x-request-id] => X-Request-ID
[cf-cache-status] => CF-Cache-Status
[report-to] => Report-To
[nel] => NEL
[server] => Server
[cf-ray] => CF-RAY
[alt-svc] => alt-svc
)
[protocol:GuzzleHttp\Psr7\Response:private] => 1.1
[stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object
(
[stream:GuzzleHttp\Psr7\Stream:private] => Resource id #58
[size:GuzzleHttp\Psr7\Stream:private] =>
[seekable:GuzzleHttp\Psr7\Stream:private] => 1
[readable:GuzzleHttp\Psr7\Stream:private] => 1
[writable:GuzzleHttp\Psr7\Stream:private] => 1
[uri:GuzzleHttp\Psr7\Stream:private] => php://temp
[customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
(
)
)
[requestId:Shopify\Clients\HttpResponse:private] => 793e5e3f-94c2-477d-a4ce-b8bd7510cfd3
[pageInfo:Shopify\Clients\RestResponse:private] =>
)
Correct ID it shown in
[Location] => Array
(
[0] => https://tradeline-5481.myshopify.com/admin/products/**7119217361032**
)
How can I get that ID? New in Shopify field, any kind of help will be appreciated.
Undefined asked
Source
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.